Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The querySelectorAll() Method</h2> <div id="myDIV" style="border:1px solid black;padding:8px;"> <h2 class="example">A Heading</h2> <p class="example">A paragraph.</p> <p class="example">A paragraph.</p> </div> <p>How many elements with class "example" in "myDIV"?</p> <p id="demo"></p> <script> const element = document.getElementById("myDIV"); const list = element.querySelectorAll(".example"); document.getElementById("demo").innerHTML = list.length; </script> </body> </html>