Check If Custom Element is Registered in Page

javascript
Published on February 11, 2021

The customElements.get() method can be used to check whether a given custom element has already been registered in the page.

This can be used to find whether a given custom element name is available in the page or not, and prevent clashes with another custom element.

If the custom element has been registered customElements.get() returns the element's class constructor. The method returns undefined if the custom element element has not been registered.

// check if <input-plus-minus> is registered
if(customElements.get('input-plus-minus') === undefined) 
	console.log('custom element not defined');
else
	console.log('custom element is defined');
In this Tutorial
    Comments
    Loading Comments