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?
iand really shouldn't use<font>tags at all.fontTags.lengthis larger than0,fontTags.lengthwill always evaluate totrue. Hence, at some momentiwill be (equal) larger thanfontTags.length. You want to compare it against the current counter, likei < fontTags.length.iwill grow more than the number of elements in thenodeList, thusfontTags[i]will be undefined.