I am trying to learn Javascript and the DOM. I would like to use a for loop to create alternative background colours for my text.
HTML:
<p> one </p>
<p> two </p>
<p> three </p>
<p> four </p>
<p> five </p>
Javascript:
var p = document.getElementByTagName(p);
var colors = ["red","green"];
for(var i=0 ; i < p.length; i++) {
p.style.background = colors;
}
Here is the fiddle: http://jsfiddle.net/tmyie/LMdXn/36/
Any help would be great :)