Example for Traversal Methods: Rewriting an Attribute


My test line

The approximative code:

 <h2 id="myh2">My test line</h2>
 document.childNodes[0].childNodes[1].childNodes[2].childNodes[1].style.color="red";
 document.getElementsByTagName("h2")[0].style.color = "yellow";
 document.getElementById("myh2").style.color = "white"; 

Effects:

Note that the first method is very sensitive to changes in the document!