Code don't work, can't read property 'className' of undefined

Posted by Arlen Beiler on Stack Overflow See other posts from Stack Overflow or by Arlen Beiler
Published on 2010-05-18T19:23:27Z Indexed on 2010/05/18 19:30 UTC
Read the original article Hit count: 323

Filed under:
|
|
|

What is wrong with this code?

var divarray = [];
var articleHTML = [];
var absHTML;
var keyHTML;
var bodyHTML = [];
var i = 0;
divarray = document.getElementById("yui-main").getElementsByTagName("div");
for ( var j in divarray) {
    if(divarray[i].className == "articleBody"){
        alert("found");
        articleHTML = divarray[i];
        break;
    }
    bodyHTML[i] = '';
    if(articleHTML[i].className == "issueMiniFeature"){continue;}
    if(articleHTML[i].className == "abstract"){absHTML = articleHTML[i]; continue;}
    if(articleHTML[i].className == "journalKeywords"){keyHTML = articleHTML[i]; continue;}
    bodyHTML[i] = articleHTML[i];
    i++;
}

The error I get is:

TypeError: Cannot read property 'className' of undefined

I am using Google Chrome.

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript