August 2019
Intermediate to advanced
158 pages
3h 13m
English
A custom element specification lets you create a custom HTML tag that can be used as its own HTML tag on the page. In order to achieve this, we need to first write a class with the functionalities associated with that HTML element, and then we need to register it so that the browser understands what this HTML tag is, and how it can be used on the page.
If you are someone who is new to the concept of classes in JavaScript, here is how you can create a class:
class myClass { constructor() { // do stuff }}
Pretty simple, right? Let's use the same class structure to create our custom element class, say HelloWorld:
class HelloWorld extends HTMLElement { constructor() { // very important // needed in every constructor // which ...Read now
Unlock full access