Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <style> div { border: 1px solid black; margin: 5px; } </style> </head> <body> <p>Click the button to add a background color to the second child node (index 1) of div.</p> <button onclick="myFunction()">Try it</button> <div id="myDIV"> <p>First p element</p> <p>Second p element</p> </div> <p><strong>Note:</strong> Whitespace inside elements is considered as text, and text is considered as nodes. In this example, index 0, 2 and 4 in DIV are text nodes.</p> <script> function myFunction() { var c = document.getElementById("myDIV").childNodes; c[1].style.backgroundColor = "yellow"; } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_node_childnodes2 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:28:22 GMT --> </html>
Result:
Try it Yourself - © w3schools.com