Check If Custom Element is Registered in Page

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');
	console.log('custom element is defined');
Related Tutorials
How to Create a HTML Custom Element
Naming Rules for Custom Elements
Creating a Custom Element Using Anonymous Class
Hiding a Custom Element Until It Gets Defined
Knowing When a Custom Element Gets Defined
Loading Comments