element.getElementsByClassName("test");Element: getElementsByClassName() method / notebook
Element: getElementsByClassName() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
document.getElementById("main").getElementsByClassName("test");element.getElementsByClassName("red test");const matches = element.getElementsByClassName("color-box");
for (let i = 0; i < matches.length; i++) {
matches[i].classList.remove("color-box");
matches.item(i).classList.add("hue-frame");
}const matches = element.getElementsByClassName("color-box");
while (matches.length > 0) {
matches.item(0).classList.add("hue-frame");
matches[0].classList.remove("color-box");
}const testElements = document.getElementsByClassName("test");
const testDivs = Array.prototype.filter.call(
testElements,
(testElement) => testElement.nodeName === "DIV",
);