Is it possible to get all elements with class a or b using getElementsByClassName() only once? I'd prefer vanilla JavaScript.
a
b
getElementsByClassName()
You can't do it with getElementsByClassName() method instead use querySelectorAll() method with comma separated class selectors.
querySelectorAll()
document.querySelectorAll('.a,.b')
2.1m questions
2.1m answers
60 comments
57.0k users