Firefox Tomorrow

web api instance property

ElementInternals: shadowRoot property

View on MDN ↗

The shadowRoot read-only property of the ElementInternals interface returns the ShadowRoot for this element.

Value

A ShadowRoot if the element has a shadow root, otherwise null.

Examples

The following example prints the value of shadowRoot to the console, immediately after calling attachInternals(). At this point the value is null. After calling attachShadow() the element has a Shadow Root, and shadowRoot returns the object representing it.

class MyCustomElement extends HTMLElement {
  constructor() {
    super();
    this.internals_ = this.attachInternals();

    console.log(this.internals_.shadowRoot); // null

    this.attachShadow({ mode: "open" });

    console.log(this.internals_.shadowRoot); // a ShadowRoot object
  }
}

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.