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

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:
Is there any better way to refer html elements by class names?
Empty Elements in HTML
Advertisements
ModuleNotFoundError: No module named 'pygments-better-html'
HTML Elements
How to extract HTML elements from a page?
How to extract HTML elements from a page?
HTML form validation using jquery
What's the proper way to test a class with private methods using JUnit?
Can a abstract class be defined without any abstract methods?
HTML Books
Shift Array Elements in Java
Save Any Eclipse Editor as HTML
ModuleNotFoundError: No module named 'auf-refer'
ModuleNotFoundError: No module named 'auf-refer'
Understanding HTML
HTML
can we mark the class with abstract..with out having any mothed in tit as abstract!!! - Java Beginners
Check for any elements exists between the current position and the limit of a buffer.
Java duplicate elements
HTML
HTML
HTML
HTML
HTML
HTML
Html
HTML
html
html
ArrayList elements
html
HTML
HTML
html
html
HTML
html
html
HTML
Simple Types elements
html
html
HTML
html
html
html
html
Html
html
Html

Ads