Here is my code:
var divarray = document.getElementById("yui-main").getElementsByTagName("div");
var articleHTML;
var absHTML;
var keyHTML;
var bodyHTML = [];
for( var i in divarray) {
if(divarray[i].className == "articleBody"){
articleHTML = divarray[i];
for( var j in articleHTML ){
bodyHTML[i] = '';
if(articleHTML[j].className == "issueMiniFeature"){continue;}
if(articleHTML[j].className == "abstract"){absHTML = articleHTML[i]; continue;}
if(articleHTML[j].className == "journalKeywords"){keyHTML = articleHTML[i]; continue;}
bodyHTML[i] = articleHTML[i];
}
break;
}
i++;
}
The error I am getting is:
SyntaxError: Unexpected token var
I am using Google Chrome
I think you mistaking JavaScript for the functionality of PHP. JavaScript does not have
foreachloops. JavaScript hasfor in, which is what you are incorrectly using and normalforloops. Use a standardforloop when dealing with arrays. You will need to use afor inloop with object literals because the index is not the simplicity of an incrementing positive integer.In JavaScript a
forloop has 3 parts in its argument separated by a semicolon as follows:* start position of incrementor (optional if the variable is previous defined with 0 or a positive integer)
* end position of incrementor
* method of incrementation
In the following examples
arrayNameis value I made up for the name of an array:The
for inloop argument has two required parts and a third part to prevent errors using anifcondition:* The value of an index to search for
* The name of the container in which to search
* The third part is an
ifconditionThe following example will return the value supplied to the “book” index of the objectName object literal.
objectNameis a name I made for an example object literal: