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";}
4 ответов
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
0
var s = document.
getElementsByTagName("span");
for(var x=0; x<s.length;x++) {
s[x].style.backgroundColor = "#33EA73";
}
- 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,
- 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