blob: 53162190a150d51308b3efd5fe51b0d3d1f77806 (
plain)
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
|
---
title: Node.isConnected
slug: Web/API/Node/isConnected
translation_of: Web/API/Node/isConnected
---
<p>{{APIRef("DOM")}}</p>
<p>The <strong><code>isConnected</code></strong> read-only property of the {{domxref("Node")}} interface returns a boolean indicating whether the Node is connected (directly or indirectly) to the context object, for example the {{domxref("Document")}} object in the case of the normal DOM, or the {{domxref("ShadowRoot")}} in the case of a shadow DOM.</p>
<h2 id="Синтаксис">Синтаксис</h2>
<pre class="syntaxbox">var isItConnected = nodeObjectInstance.isConnected</pre>
<h3 id="Return_value">Return value</h3>
<p>A {{domxref("Boolean")}} that is <code>true</code> if the node is connected to its relevant context object, and <code>false</code> if not.</p>
<h2 id="Пример">Пример</h2>
<p>Стандартный DOM пример:</p>
<pre class="brush: js"><code class="language-html">let test = document.createElement('p');
console.log(test.isConnected); // returns false
document.body.appendChild(test);</code>
<code class="language-html">console.log(test.isConnected); // returns true</code>
</pre>
<p>A shadow DOM example:</p>
<pre class="brush: js">// 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</pre>
<p> </p>
<h2 id="Спецификация">Спецификация</h2>
{{Specifications}}
<h2 id="Поддержка_Браузерами">Поддержка Браузерами</h2>
<div>
<p>{{Compat}}</p>
</div>
|