0
Why is JS getElementsByClassName method not working?
Hi all, I have an issue here. I'm totally new to javascript and I just completed the course here, so i have been playing around with the codes. I came to realize that document.getElementsByClassName is not working at all or is it? Where could I be wrong? or is there another alternative to this?
2 Antworten
+ 8
Working fine for me
remember that document.getElementsByClassName returns a collection of elements and not just a single element like document.getElementById so you have to either iterate on the elements (as i did in the code below, changeAll() function) OR choose specificly the one you want by its index (also in the code below, changeMiddle() function):
var boxes = document.getElementsByClassName("boxes");
var myBox = boxes[1];
https://code.sololearn.com/WHYS5Za1jiJ1/?ref=app
0
thanks Burey