Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM customElements get() method

  • Last Updated : 14 Jul, 2020

The customElements get() method returns the constructor used for a previously-defined custom element.


constructor = customElements.get('custom-element-name');


  • name: The name of the custom element whose constructor you want to return.

Return value: This method returns the constructor for the custom element, or undefined if there is no custom element definition with that name.

Example: In this example, we will define a custom-element and then will get its constructor using this method.

    <title>get() method</title>
<body style="text-align:center;">
    <h1 style="color:green;">  
    HTML | customElements get() method
    <button onclick = "Geeks();">
    click here to get constructor
    <p id="a"
        var a = document.getElementById("a");
        function Geeks() {
            class CustomEl extends HTMLElement {
                  constructor() {
                    this.attachShadow({ mode: 'open' })
                    this.shadowRoot.innerHTML = `
                      <h1 style="color:green;">  
                        GeeksforGeeks Custom Element Data
window.customElements.define('gfg-custom-element', CustomEl);


Before Clicking Button:

After Clicking Button: In the console, the constructor can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!