With your code, FF returns an array of length 10, IE returns length 8.
With my code, both return length 22.
Code:
var tgNm = obj.childNodes[i].tagName? obj.childNodes[i].tagName.toUpperCase(): undefined;
//No point in making tgNm undefined, just make it an empty string.
var tgNm = obj.childNodes[i].tagName? obj.childNodes[i].tagName.toUpperCase(): "";
Looking at your original first-post code, it looks like you only want the LI elements. If that is the case, just use
Code:
navNode(obj){return obj.getElementsByTagName("li");}
If you want to filter out some of the tags, try
Code:
function navNode(obj) {
var results = [];
for(var i=0; i<obj.childNodes.length; i++) {
var tgNm = obj.childNodes[i].tagName?obj.childNodes[i].tagName.toUpperCase():"";
if(tgNm=="OL" || tgNm=="UL" || tgNm=="LI") {
if(tgNm!="OL") results[results.length] = obj.childNodes[i]; //Or something like that if you don't want OL for instance.
results = results.concat(navNode(obj.childNodes[i])); //I took out the temp because errors don't seem to arise when concatenating an empty array to another.
}
}
return results;
}
If you need more help, I guess you can clarify what exactly you want this function to return and/or do.
Bookmarks