👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.
In JavaScript, how to select element by class?
In JavaScript, the getElementsByClassName(className)
method returns an array-like object of all child elements which have the given class name. Here are some examples:
// Get all elements from the document that have the class 'center'
document.getElementsByClassName('center')
// Get all elements that have a class of 'bold', inside of an element with ID 'container'
document.getElementById('container').getElementsByClassName('bold')