运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 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>