Cory Rylan
Dodge City Slots. Dodge City Slots. Dog Pound Dollars. Dog Pound Dollars. Dollars to Donuts. Dollars to Donuts. You’ve just discovered the biggest online, free slots library. Like thousands of slots players who use VegasSlotsOnline.com every day, you now have instant access to over 7780 free online slots that you can play right here.
- 3 minutes
![Slot Web Slot Web](/uploads/1/3/4/3/134374847/216833707.png)
Web Components provide a component model to the Web. Web Components, instead of being a single spec, is a collection of several stand-alone Web technologies. Often Web Components will leverage Shadow DOM features. Shadow DOM is commonly used for CSS encapsulation. However, Shadow DOM has another useful feature called Slots.
The Slot API is a content projection API that allows HTML content from the host application to be rendered into your component template. Common examples of this are things like cards and modals.
Here is a minimal example of a Custom Element using the Slot API.
The tags' content can be rendered into our template we defined. The browser render the content wherever the
<slot>
element is placed. If we look at what the browser renders, we will see something like this:The content is projected and rendered within the template of our component. Often there are use cases, whereas the component author we would like to know about any updates to the content provided by the slot element. We can achieve this by adding an event listener in our component for the
slotchange
Vikings free spins. event.![Websites Websites](/uploads/1/3/4/3/134374847/483149832.png)
This event will fire whenever any content has changed within the slot. To test this, we can use our component and dynamically update the content to see the event update.
In this example, every one second, we can set the
textContent
or the innerHTML
of the component and see the slotchange
event fire within the x-component
. Powerball winning numbers winning amounts.We can easily render content into our component templates and listen for content updates. But there is one interesting exception to this rule. While the event will happen whenever
textContent
or innerHTML
are set, the event will not occur if a textNode
reference is updated dynamically. Let's take a look at an example.Instead of directly setting the
textContent
or innerHTML
of our element we create a text node. While not an HTML element, the text node allows us to hold a reference in memory we can update at a later point. So if we go back to our interval, we will see the text change, but the event is no longer triggered.This behavior can be a bit unexpected at first. Many JavaScript frameworks will leverage text nodes to optimize for performance. The short rule to remember is
slotchange
only fires when the HTML DOM has changed either by a DOM/Text Node from being added or removed. Check out the full working example below!