0

i'm not sure...but i think i dont understand enouph why we use "for" to change elemets style?

for example here: var s = document.getElementsByTagName("span"); for(var x = 0; x<s.length; x++) {s[x].style.backgroundColor = "#33EA73";}

11th Jan 2017, 2:14 AM
Nurabdurashid
Nurabdurashid - avatar
4 Answers
0
this is the answer to var s = document. getElementsByTagName(" "); (var x=0; x<s.length;x++) { s[ ].style.backgroundColor = "#33EA73"; } 1= span 2=for 3=x
5th Jun 2017, 8:25 AM
luutu wilson
luutu wilson - avatar
0
var s = document. getElementsByTagName("span"); for(var x=0; x<s.length;x++) { s[x].style.backgroundColor = "#33EA73"; }
20th Oct 2020, 8:47 AM
BACHIR EL HALLAK
BACHIR EL HALLAK - avatar
- 1
that's just how you do it in javascript. you put all the span in array and iterate over it and assigning style for each span. in normal CSS use CSS selector to change style,
11th Jan 2017, 3:52 AM
Yuliana
Yuliana - avatar
- 1
The "for" is just for looping over the elements in the "s" array. You can do the same without the loop: var s=document.getElementByTagName("span"); s[0].style.backgroundColor="#33EA73"; s[1].style.backgroundColor="#33EA73"; // and so forth
13th Jan 2017, 11:32 AM
L Cilliers
L Cilliers - avatar