+ 1

get element by class name NOT WORKING

actually i know that you need to access the element by arr{0].style.dislay .but i have got 8 element together to select and can't do it one by one also the code will become very long so i want to know how can I do it all together !

13th Oct 2020, 8:47 AM
Shreyansh Shah
Shreyansh Shah - avatar
2 Answers
+ 4
You forgot to attach your code with the Description ☝
13th Oct 2020, 8:56 AM
Ipang
+ 4
Just use a for loop; elems = document.getElementsByClassName("class_name"); for (let i = 0; i < elems.length; i++) { elems[i].style.display = ...; }
13th Oct 2020, 9:08 AM
Russ
Russ - avatar