运行 ❯
建立您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The querySelectorAll() Method</h2> <p>Add a background color to the first p element with class="example":</p> <h2 class="example">A heading</h2> <p class="example">A paragraph.</p> <p class="example">A paragraph.</p> <script> const nodeList = document.querySelectorAll("p.example"); nodeList[0].style.backgroundColor = "red"; </script> </body> </html>