ZVON > References > DOM2 Reference

item (method )

Owning interface and usage:  
NodeList.item(index)

Member of these other interfaces:  
none

Description:  
Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

Parameters:  
unsigned index  -  Index into the collection.

Returns:  
Node -  The node at the indexth position in the NodeList, or null if that is not a valid index.

Exceptions:  
none


Example:
Text in the first DIV.
Some text in the second DIV.
Some text and element in the third DIV.
We can try another elements. It will be much more interesting.
Text in the last DIV.
Source:
   <div id="doc">
     <div>
       Text in the first DIV.
     </div>
     <div id="DDD" class="secondClass">
       Some text in the second DIV.
     </div>
     <div class="thirdClass">
       Some text and <span id="SSS">element</span> in the third DIV.
     </div>
     <div class="fourthClass">
       We can try <i>another elements</i>.
       It will be much more <b>interesting</b>.
     </div>
     <div>
       Text in the last DIV.
     </div>
   </div>
     
JavaScript:
  var main = document.getElementById('doc');
  var collection = main.getElementsByTagName('DIV');
  var output1 = collection.item(2).firstChild.nodeValue;
  var output2 = collection[2].firstChild.nodeValue;
Output:
desired your browser
output1: Some text and
output2: Some text and