Is there any better way to refer html elements by class names?

Hi,

Are there any other best practices to get an HTML element by class name?

let left = document.getElementsByClassName("pro-left");

for (let i = 0; i < right.length; i++) {

    left[i].addEventListener("click", function () {
        console.log("Clicked");
    }
}
View Answers









Related Tutorials/Questions & Answers:
Advertisements