執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
轉到 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>