我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

The host read-only property of the ShadowRoot returns a reference to the DOM element the ShadowRoot is attached to.

Syntax

var element = shadowRoot.host

Value

A  DOM Element.

Examples

let customElem = document.querySelector('my-shadow-dom-element');
let shadow = customElem.shadowRoot;

  ...

// return the original host element sometime later
let hostElem = shadow.host;

Specifications

Specification Status Comment
DOM
The definition of 'ShadowRoot.host' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support53 No1

63

592 3

No4010.1
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5353 No1

63

592 3

4010.16.0

1. Under consideration

2. See bug 1205323

3. From version 59: this feature is behind the dom.webcomponents.shadowdom.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

文档标签和贡献者

最后编辑者: ExE-Boss,