concept custom element in category elm

appears as: custom element, custom elements
Elm in Action

This is an excerpt from Manning's book Elm in Action.

This two-argument pattern is consistent throughout the Html module, and it’s worth following if you ever decide to make a custom element of your own by using the node function. We’ll see more of the node function in chapter 5.

Custom elements are a part of the Web Components specification. Here’s how they work:

  • We write some JavaScript to define a new DOM element type. In this case, the new element will be called a <range-slider>. (Custom elements must have a dash in their names.)
  • Listing 5.1. Registering the custom element
    <script>                                                        #1
        class RangeSlider extends HTMLElement {                     #2
            connectedCallback() {                                   #3
                var input = document.createElement("input");        #4
                this.appendChild(input);                            #5
            }
        }
    
        window.customElements.define("range-slider", RangeSlider);  #6
    </script>
    </head>