I'm trying to get the innerHTML of red font tags...
var fontTags = document.getElementsByTagName('font');
var reds = [];
var j = 0;
var i = 0; // ETA this line
for (i;i<=fontTags.length;i++) { // ETA the 'i<='
if (fontTags[i].getAttribute('color') == 'RED') {
reds[j] = fontTags[i].innerHTML;
j++;
}
}
The javascript console is informing me that "fontTags[i]" is undefined. I've tried no declaration, declaring with 'new Array()'... same thing. Help?
Your for
loop is missing a proper loop-condition.
for (i=0;i<fontTags.length;i++) {
if (fontTags[i].getAttribute('color') == 'RED') {
reds[j] = fontTags[i].innerHTML;
j++;
}
}