aboutsummaryrefslogtreecommitdiff
path: root/files/it/web/api/domtokenlist/item/index.html
blob: c81eedcbc9899c5bb0ffa00c2008832d91176e86 (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
---
title: DOMTokenList.item()
slug: Web/API/DOMTokenList/item
translation_of: Web/API/DOMTokenList/item
---
<p>{{APIRef("DOM")}}</p>

<p>Il metodo <strong><code>item()</code></strong> dell'interfaccia {{domxref("DOMTokenList")}} restituisce un elemento nell'elenco per il suo indice.</p>

<h2 id="Sintassi">Sintassi</h2>

<pre class="syntaxbox">tokenList.item(index);</pre>

<h3 id="Parametri">Parametri</h3>

<dl>
 <dt>index</dt>
 <dd>Una {{domxref("DOMString")}} che rappresenta l'indice dell'elemento che si desidera restituire.</dd>
</dl>

<h3 id="Valore_di_ritorno">Valore di ritorno</h3>

<p>Una {{domxref("DOMString")}} che rappresenta l'elemento restituito. Restituisce <code>undefined</code> se il numero è maggiore o uguale alla lunghezza della lista.</p>

<h2 id="Esempi">Esempi</h2>

<p>Nel seguente esempio recuperiamo l'elenco di classi impostate su un elemento {{htmlelement("span")}} come <code>DOMTokenList</code> usando {{domxref("Element.classList")}}. Quindi recuperiamo l'ultimo elemento nell'elenco usando <em>item(length-1)</em> e lo scriviamo nel <code>&lt;span&gt;</code>'s {{domxref("Node.textContent")}}.</p>

<p>Innanzitutto, l'HTML:</p>

<pre class="brush: html">&lt;span class="a b c"&gt;&lt;/span&gt;</pre>

<p>Ora JavaScript:</p>

<pre class="brush: js">var span = document.querySelector("span");
var classes = span.classList;
var item = classes.item(classes.length-1);
span.textContent = item;</pre>

<p>L'output è simile a questo:</p>

<p>{{ EmbedLiveSample('Examples', '100%', 60) }}</p>

<h2 id="Specifiche">Specifiche</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specificazione</th>
   <th scope="col">Stato</th>
   <th scope="col">Commento</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG','#dom-domtokenlist-item','item()')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Definizione iniziale</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilità_con_i_Browser">Compatibilità con i Browser</h2>

<div>


<p>{{Compat("api.DOMTokenList.item")}}</p>
</div>