I need to bind the onclick function in each link of a web page, so I use this function:
var links = document.getElementsByTagName('a');// total 5 links
for(var key in links){
//always be true in IE, But just be true from second latest in chrome
alert(isNaN(parseInt(key)));
if(isNaN(parseInt(key))){
break;
}else{
...
}
}
Please help.
Update:
It seems is the problem of for (var key in links), when is in IE, the key become the Id of the link, but it’s just number in Chrome.
You are enumerating other stuff beyond your anchor tags, and some of this stuff is supposed to be
NaN. Use a regularforloop: