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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
---
title: Node.nextSibling
slug: Web/API/Node/nextSibling
translation_of: Web/API/Node/nextSibling
---
<div>{{APIRef("DOM")}}</div>
<p><span class="seoSummary">La proprietà di sola lettura <code><strong>Node.nextSibling</strong></code> restituisce il nodo immediatamente successivo a quello specificato nei {{domxref("Node.childNodes","childNodes")}}, del loro genitore o restituisce <code>null</code> se il nodo specificato è l'ultimo figlio nell'elemento genitore.</span></p>
<h2 id="Sintassi">Sintassi</h2>
<pre class="syntaxbox"><var>nextNode</var> = <var>node</var>.nextSibling
</pre>
<h2 id="Appunti">Appunti</h2>
<div>
<p>I browser basati su Gecko inseriscono nodi di testo in un documento per rappresentare gli spazi bianchi nel codice sorgente. Pertanto, un nodo ottenuto, ad esempio, utilizzando <a href="/it/docs/Web/API/Node/firstChild" title="The Node.firstChild read-only property returns the node's first child in the tree, or null if the node has no children."><code>Node.firstChild</code></a> o <a href="/it/docs/Web/API/Node/previousSibling" title="The Node.previousSibling read-only property returns the node immediately preceding the specified one in its parent's childNodes list, or null if the specified node is the first in that list."><code>Node.previousSibling</code></a> può fare riferimento a un nodo di testo di spazi bianchi piuttosto che all'elemento effettivo che l'autore intendeva ottenere.</p>
<p>Vedi <a href="/en-US/docs/Web/Guide/DOM/Whitespace_in_the_DOM">Whitespace in the DOM</a> e <a class="external" href="http://www.w3.org/DOM/faq.html#emptytext" rel="noopener">W3C DOM 3 FAQ: Why are some Text nodes empty?</a> per maggiori informazioni.</p>
</div>
<p>{{domxref("Element.nextElementSibling")}} può essere usato per ottenere l'elemento successivo saltando eventuali nodi di spazi vuoti, altro testo tra elementi o commenti.</p>
<h2 id="Esempio">Esempio</h2>
<pre class="brush:html"><div id="div-1">Here is div-1</div>
<div id="div-2">Here is div-2</div>
<script>
var el = document.getElementById('div-1').nextSibling,
i = 1;
console.group('Siblings of div-1:');
while (el) {
console.log(i, '. ', el.nodeName);
el = el.nextSibling;
i++;
}
console.groupEnd();
</script>
/**************************************************
The console displays the following:
Siblings of div-1
1. #text
2. DIV
3. #text
4. SCRIPT
**************************************************/
</pre>
<p>Nell'esempio precedente, i nodi, <code>#text</code> sono inseriti nel DOM in cui si verifica lo spazio bianco tra i tag (ad esempio dopo il tag di chiusura di un elemento e prima del tag di apertura del successivo).</p>
<p>La possibile inclusione di nodi di testo deve essere consentita quando si attraversa il DOM utilizzando <code>nextSibling</code>. Vedi le risorse <a href="#Appunti">nella sezione Appunti</a>.</p>
<h2 id="Specifiche">Specifiche</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specifica</th>
<th scope="col">Stato</th>
<th scope="col">Commento</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('DOM WHATWG', '#dom-node-nextsibling', 'Node.nextSibling')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td>Nessun cambiamento</td>
</tr>
<tr>
<td>{{SpecName('DOM2 Core', 'core.html#ID-6AC54C2F', 'Node.nextSibling')}}</td>
<td>{{Spec2('DOM2 Core')}}</td>
<td>Nessun cambiamento</td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'level-one-core.html#attribute-nextSibling', 'Node.nextSibling')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>Definizione iniziale</td>
</tr>
</tbody>
</table>
<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2>
<p>{{Compat("api.Node.nextSibling")}}</p>
<h2 id="Vedi_anche">Vedi anche</h2>
<ul>
<li>{{domxref("Element.nextElementSibling")}}</li>
</ul>
|