Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  87] [ 6]  / answers: 1 / hits: 18787  / 6 Years ago, sat, april 7, 2018, 12:00:00

Is it possible to find more than one ID (e.g. div1, div2, div3) by using document.querySelector()?



If not then is there a alternative solution?


More From » html

 Answers
71

Yes, you can by do that. First of all, in order to retrieve multiple elements, you'll have to use querySelectorAll. Second, you just separate all the ids with commas, it's no different from CSS.



var nodes = document.querySelectorAll('#a, #b, #c');


This will give you a NodeList of all the elements matching the IDs.


[#54731] Wednesday, April 4, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cindyanyssam

Total Points: 483
Total Questions: 94
Total Answers: 100

Location: Barbados
Member since Sat, May 28, 2022
2 Years ago
;