Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<style>
.example {
  border: 1px solid black;
  margin: 5px;
}
</style>
<body>
<h1>The Document Object</h1>
<h2>The querySelectorAll() Method</h2>
<h3>Change the background color of all p elements:</h3>
<h1>A h1 element</h1>
<div>A div element</div>
<p>A p element.</p>
<p>A p element.</p>
<div class="example">
  <p>A p element inside a div element.</p>
</div>
<script>
const nodeList = document.querySelectorAll("p");
for (let i = 0; i < nodeList.length; i++) {
  nodeList[i].style.backgroundColor = "red";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_queryselectorall_loop_p by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 05 Sep 2022 15:18:57 GMT -->
</html>