Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
150
rated 0 times [  152] [ 2]  / answers: 1 / hits: 99029  / 8 Years ago, mon, may 16, 2016, 12:00:00

Is it possible to get all elements with class a or b using getElementsByClassName() only once? I'd prefer vanilla JavaScript.


More From » html

 Answers
35

You can't do it with getElementsByClassName() method instead use querySelectorAll() method with comma separated class selectors.



document.querySelectorAll('.a,.b')

[#62154] Friday, May 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
paola

Total Points: 675
Total Questions: 115
Total Answers: 95

Location: Laos
Member since Tue, Jul 7, 2020
4 Years ago
;