getElementsByTagName
method returns all of the elements of the specified tag name as an array. The following example gets all paragraph elements of the page and changes their content. JS
let arr = document.getElementsByTagName("p");
for (let x = 0; x < arr.length; x++) {
  arr[x].innerHTML = "Hi there";
}
HTML of the example
<p>Hi</p>
<p>Hey</p>
<p>Hello</p>
<div>Hello there</div>
Note: We used the
length
property of the
array
to loop through all the selected elements in the above example
by Valeri Tandilashvili
4 years ago
JavaScript
DOM
2
Pro tip: use ```triple backticks around text``` to write in code fences