Node: isConnected-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Die schreibgeschützte isConnected-Eigenschaft des Node-Interfaces gibt einen booleschen Wert zurück, der anzeigt, ob der Node (direkt oder indirekt) mit einem Document-Objekt verbunden ist.

Wert

Ein boolescher Wert, der true ist, wenn der Node mit seinem relevanten Kontextobjekt verbunden ist, und false, wenn nicht.

Beispiele

Standard DOM

Ein Beispiel aus dem Standard-DOM:

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

Shadow DOM

Ein Beispiel aus dem Shadow-DOM:

js
// Create a shadow root
const shadow = this.attachShadow({ mode: "open" });

// Create some CSS to apply to the shadow DOM
const 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;
  positions: 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

Spezifikationen

Specification
DOM
# ref-for-dom-node-isconnected①

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
isConnected

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support