Search code examples
javascriptcssweb-componentshadow-dom

What is the alternative for Element.createShadowRoot()?


I'm using this piece of code:

function setShadowDOM(i, css){
    [].forEach.call(document.getElementsByTagName(i), function(hostVal) {
        var _root = hostVal.createShadowRoot();
            _root.innerHTML = '<style>:host ' + css + '</style><content></content>';
    })
}

I'm also reading this.

How to solve this? What would be the alternative?


Solution

  • Now you can use attachShadow() instead of createShadowRoot():

    The Shadow DOM v1 is a DOM Living Standard.

    Edge will soon adopt the Chromium engine, then it will be Shadow DOM v1 compliant.