The
getElementsByClassName()
method returns a collection of all elements (as an array) in the document with the specified class name. JS
var arr =  document.getElementsByClassName("demo");
//accessing the second element
arr[1].innerHTML = "Hi";
HTML
<div class="demo">1</div>
<div class="demo">2</div>
by Valeri Tandilashvili
4 years ago
JavaScript
DOM
2
Pro tip: use ```triple backticks around text``` to write in code fences