how to get all elements with same class in javascript code example

Example 1: how to get all elements with same class in javascript

var elements = document.getElementsByClassName("class-1");
for (var i = 0, len = elements.length; i < len; i++) {
    // elements[i].style ...
}

Example 2: javascript get all classes

var allHiddenElements = document.getElementsByClassName("hidden");

Example 3: javascript document object model getElementsByClassName

document.getElementsByClassName('test')

Example 4: javascript get all elements by class starting with

document.querySelectorAll("[class^=page]")