22
loading...
This website collects cookies to deliver better user experience
<my-profile name="Marty" lastname="Mcfly"></my-profile>
<template>
tag, have the advantage of not being loaded during the initial page loading, therefore, not rendered or added to the DOM. Inner scripts, images and audio won't be executed, loaded or played until we'll use them from JS. The browser engine only analyses the code in order to check that the template content is valid.<template>
<div class="profile-picture">
<img src="marty.png" alt="Marty Mcfly" />
</div>
<div class="name">Marty Mcfly</div>
</template>
document.querySelector()
we won't find any element of the web component.<div class="button">
, if inside the web component there was also a div
with the same class, it would not be affected by the outside styles.<my-profile name="Marty" lastname="Mcfly">
#shadow-root
<div class="profile-picture">
<img src="marty.png" alt="Marty Mcfly" />
</div>
<div class="name">Marty Mcfly</div>
</my-profile>
<slot />
, a.k.a. Light DOM. As previously stated, Slots are the way we have to customize the content of our web component. As they are not part of Shadow DOM, and therefore, are not encapsulated, they are affected by page styles and can be queried. There are some exceptions and details to take into account related to Shadow DOM that will be analyzed in detail later in future posts.type="module"
:import { formatter } from "DateFormatter";
<script type="module" src="my-web-component.js"></script>