How to modify all 3 elements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How to modify all 3 elements

Can someone tell me why this thing didn't work : Supplies = document.getElementsByClassName ("supplie")[0]; Supplies.style.color="red"; It just color the first elements ==? if I have 3 elements how can I modified all 3 of it?

20th Mar 2017, 10:33 AM
Leon lit
Leon lit - avatar
3 Answers
+ 4
because by id you said supplie and not supplies it doesnt know its an array. add the s and it should work just fine
20th Mar 2017, 1:40 PM
Andre van Rensburg
Andre van Rensburg - avatar
+ 2
var supplies = document.getElementByClassName("supplie"); for (var x=0;x<supplies.length;x++) { spplies[x].style.color="red"; }
20th Mar 2017, 1:43 PM
ali mhrez
ali mhrez - avatar
+ 1
TRY THIS ONE Supplies = document.getElementsByClassName ("supplies")[0]; Supplies.style.color="red";
21st Mar 2017, 1:01 PM
Ludovick Stanley, K
Ludovick Stanley, K - avatar