<!DOCTYPE html>
<html>
<body>
<h1>The Element Object</h1>
<h2>The querySelectorAll() Method</h2>
<p>Add a background color to all elements with class="example" in "myDIV":</p>
<div id="myDIV" style="border:1px solid black">
<h2 class="example">A Heading</h2>
<p class="example">A p element.</p>
<p class="example">A p element.</p>
<p>A p <span class="example">element</span>.</p>
</div>
<script>
const element= document.getElementById("myDIV");
const list = element.querySelectorAll(".example");
for (let i = 0; i < list.length; i++) {
list[i].style.backgroundColor = "red";
}
</script>
</body>
</html>