Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

The isConnected read-only property of the Node interface returns a boolean indicating whether the node is connected (directly or indirectly) to the context object, for example the Document object in the case of the normal DOM, or the ShadowRoot in the case of a shadow DOM.

Syntax

var isItConnected = nodeObjectInstance.isConnected

Return value

A Boolean that is true if the node is connected to its relevant context object, and false if not.

Examples

Standard DOM

A standard DOM example:

let test = document.createElement('p');
console.log(test.isConnected); // Returns false
document.body.appendChild(test);
console.log(test.isConnected); // Returns true

Shadow DOM

A shadow DOM example:

// Create a shadow root
var shadow = this.attachShadow({mode: 'open'});

// Create some CSS to apply to the shadow dom
var style = document.createElement('style');
console.log(style.isConnected); // returns false

style.textContent = '.wrapper {' +
                       'position: relative;' +
                    '}' +

                     '.info {' +
                        'font-size: 0.8rem;' +
                        'width: 200px;' +
                        'display: inline-block;' +
                        'border: 1px solid black;' +
                        'padding: 10px;' +
                        'background: white;' +
                        'border-radius: 10px;' +
                        'opacity: 0;' +
                        'transition: 0.6s all;' +
                        'position: absolute;' +
                        'bottom: 20px;' +
                        'left: 10px;' +
                        'z-index: 3;' +
                      '}' +

// Attach the created style element to the shadow dom

shadow.appendChild(style);
console.log(style.isConnected); // Returns true

Specifications

Specification Status Comment
DOM
The definition of 'isConnected' in that specification.
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
isConnectedChrome Full support 51Edge No support NoFirefox Full support 53IE No support NoOpera Full support 38Safari Full support 10.1WebView Android Full support 51Chrome Android Full support 51Edge Mobile No support NoFirefox Android Full support 45Opera Android Full support 41Safari iOS Full support 10.1Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
Mitwirkende an dieser Seite: mdnwebdocs-bot, mfluehr, jpmedley, fscholz, chrisdavidmills
Zuletzt aktualisiert von: mdnwebdocs-bot,