<!DOCTYPE html>
<html>
<head>
<style>
.example {
border: 1px solid black;
margin: 5px;
}
</style>
</head>
<body>
<h1>A h1 element</h1>
<div>A div element</div>
<p>A p element.</p>
<p>Another p element.</p>
<div class="example">
<p>A p element inside a div element.</p>
</div>
<p>Click the button to change the background color of all p elements in the document.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> The querySelectorAll() method is not supported in Internet Explorer 8 and earlier versions.</p>
<script>
function myFunction() {
var x = document.querySelectorAll("p");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.backgroundColor = "red";
}
}
</script>
</body>
</html>