-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
83 lines (61 loc) · 1.63 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "Node: isConnected property"
short-title: isConnected
slug: Web/API/Node/isConnected
page-type: web-api-instance-property
browser-compat: api.Node.isConnected
---
{{APIRef("DOM")}}
The read-only **`isConnected`** property of the {{domxref("Node")}} interface
returns a boolean indicating whether the node is connected
(directly or indirectly) to a {{domxref("Document")}} object.
## Value
A boolean value that is `true` if the node is connected to its relevant context object,
and `false` if not.
## Examples
### Standard DOM
A standard DOM example:
```js
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:
```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
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Node.prototype.isConnected polyfill](https://gist.github.com/eligrey/f109a6d0bf4efe3461201c3d7b745e8f)