运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The children Property</h2> <p>Change background of the second child element (index 1) of "myDIV":</p> <div id="myDIV"> <p>I am a paragraph</p> <p>I am a paragraph</p> <p>I am a paragraph</p> </div> <script> const collection = document.getElementById("myDIV").children; collection[1].style.backgroundColor = "yellow"; </script> </body> </html>