Bob van Luijt Bob van Luijt - 2 months ago 9
CSS Question

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?

Answer

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

The Shadow DOM v1 is a DOM Living Standard.

You can support its implementation for Edge and for Firefox.

Comments