37
loading...
This website collects cookies to deliver better user experience
<script src="[REPLACE_WITH_JS_FILE_LOCATION]"></script>
class MyComponent extends HTMLElement {
constructor() {
super();
//Add/Initialize the state of our components here
}
}
class MyComponent extends HTMLElement {
constructor() {
super();
//Attaching Shadow DOM
this.attachShadow({mode:'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
const template = document.createElement('template');
template.innerHTML = `
<style>
//Add the required styling for your component here
</style>
<div class="[Any_class_name_you_want]" id="[Can_also_give_a_id]">
//Add the required content here
</div> `;
class MyComponent extends HTMLElement ....
<my-component my_attribute="some_value">
</my-component>
class MyComponent extends HTMLElement {
...
...
this.attachShadow({mode:'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
this.shadowRoot.querySelector('div').innerText = this.getAttribute('my_attribute');
...
window.customElements.define('my-component', MyComponent);