Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<style>
div {
  border: 1px solid black;
  padding: 16px;
  font-size: 32px;
}
</style>
<body>
<h1>The Element Object</h1>
<h2>The getElementsByTagName() Method</h2>
<div id="myDIV">
  <p>I am a paragraph.</p>
  <p>I am a paragraph.</p>
  <p>I am a paragraph.</p>
</div>
<p>Click "Change" to change the color of all p elements in "myDIV".</p>
<button onclick="myFunction()">Change</button>
<script>
function myFunction() {
  const div = document.getElementById("myDIV");
  const nodes = div.getElementsByTagName("p");
  for (let i = 0; i < nodes.length; i++) {
    nodes[i].style.color = "red";
  }
}
</script>
</body>
</html>