What Is The Best Way To Define HTML Custom Element? | Web Components | Amit Padhiyar (Saatody)
Define class with class name and outside of the define() function is the best way to create custom element.
<script>
class HelloMSG extends HTMLElement{
constructor(){
super();
console.log("constructor");
}
}
window.customElements.define("hello-msg",HelloMSG);
</script>
There is one thing that prove why i recommended to define HTML custom element like this.<script>
const msg = new HelloMSG();
document.body.appendChild(msg);
</script>
For append my HTML custom element using JavaScript.
Comments
Post a Comment