Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <head> <style> div { border: 1px solid black; margin: 5px; } </style> </head> <body> <h1>The Element Object</h1> <h2>The childNodes Property</h2> <div id="myDIV"> <p>First p element</p> <p>Second p element</p> </div> <p>Add a background color to the second child node of the div.</p> <p>Whitespace inside elements is considered text nodes. In this example, index 0, 2 and 4 in myDIV are text nodes.</p> <script> document.getElementById("myDIV").childNodes[1].style.backgroundColor = "yellow"; </script> </body> </html>