0

How do you change all classes at once?

Lets say i have an class call "Rev" and this class is used multiple times... Now I have decided to add an onclick="str()" to something, so when pressed, it will do this next function: function str(){ var allRev = document.getElementsByClassName("Rev"); allRev[ ].style.width = "900px"; }; // it will change the width Now i want it to change all of the elements with the class name "Rev" without having to type it out eg. [0,1,2,3...] Because if this number of classes were to increase constantly, then this will become a real drag, so how can i select all of the classes at once?

11th Jan 2019, 11:00 PM
Stephen Van Der Westhuizen
Stephen Van Der Westhuizen - avatar
2 Answers
+ 4
for(var i=0; i<allRev.length; ++i){ var currRev= allRev[i]; currRev.style.width= '900px'; }
11th Jan 2019, 11:38 PM
KrOW
KrOW - avatar
+ 1
Thank you!
12th Jan 2019, 8:04 PM
Stephen Van Der Westhuizen
Stephen Van Der Westhuizen - avatar