HTML DOM Accessing Nodes (Cont.)


DOM Node List
The getElementsByTagName method returns a node-list. A node-list is an array of nodes. The code on the right selects all <p> nodes in a node-list. The index starts at 0.



   


DOM Node List Length
The length property defines the number of nodes in a node-list. You can loop through a node-list by using the length property. The example performs the following two tasks:
  1. Get all <p> element nodes.
  2. For each <p> element, output the value of its text node.



   


Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.

     





      Tragedy is when I cut my finger.    
      Comedy is when you fall into an open sewer and die.    
      — Mel Brooks on the difference between comedy and tragedy