I have this code in a function, and want to shorten it - it applies the same style to every item in an array.
document.getElementById(divsArray[0]).style.visibility = 'hidden';
document.getElementById(divsArray[1]).style.visibility = 'hidden';
document.getElementById(divsArray[2]).style.visibility = 'hidden';
document.getElementById(divsArray[3]).style.visibility = 'hidden';
NO answer to date worked (Because I am looping thru the code??)
Resolved it by setting only the previously displayed slide visibility to hidden
x = i;
i = i+1;
document.getElementById(divsArray[x]).style.visibility = 'hidden';
for(var i=0;i<4;i++)
and you usedfor(i=0;i<4;i++)
. The answers are essentially the same, but slightly different. If I answered 4 seconds ahead of you, would you delete your answer, even though you know you're more right than me? That's why no one deleted their answers -- they're all slightly different, and they're leaving it up to Rhys to decide. – Chowchowi
and go on to explain that I prefer this style because for(var... can be misleading to readers familiar with other languages where for introduces scope - but to leave the answer stand, assuming that a reader unfamiliar with looping will somehow know my reasoning, does more harm than good). And re: the free market: I'm participating in that market... – Krever