{{APIRef('Shadow DOM')}} {{Non-standard_header}}
The Element.attachShadow()
method attatches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot
.
Syntax
var shadowroot = element.attachShadow(shadowRootInit);
Parameters
shadowRootInit
- A
ShadowRootInit
dictionary, having the following field:mode
: A string specifying the encapsulation mode for the shadow DOM tree. One of:open.
Specifies open encapsulation mode.closed.
Specifies closed encapsulation mode.
Returns
Returns a {{domxref("ShadowRoot")}}.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('Shadow DOM', '#widl-Element-attachShadow-ShadowRoot-ShadowRootInit-shadowRootInitDict', 'attachShadow()')}} | {{Spec2('Shadow DOM')}} | Initial definition. |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome(53.0)}} | {{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatNo}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} |