开发者

Equivalent of "parentNode" in internet explorer

I wrote some code that modifies the images on a web开发者_如何学JAVApage. Works with firefox and safari. But tryingto get it to work with Internet explorer has got me stumped. What is the equivalent of "parentNode" in explorer? Or how does one trick it into working?

images = document.getElementsByTagName('img')
parms = {};

for (a=0;a < images.length;a++){
    parent = images[a].parentNode; // <-- What to substitute for explorer?
    parms[a] = {};
    parms[a].bigsrc=parent.getAttribute("href");
    parms[a].w_o = images[a].width;
    parms[a].h_o = images[a].height;
    parms[a].IsBig = false;
    parms[a].loaded = false;
    images[a].border=0;
    parent.setAttribute("href","javascript:MakeBig('"+a+"')");
}


The problem is with the assignment of the parentNode to a var called "parent." This seems to be a reserved word in IE that breaks the code. Change the var name and it should work.


parentNode works fine in IE (except in certain cases, very likely irrelevant here). The error is almost certainly elsewhere in your code.


Are you expecting the parentNode to be an anchor? It looks like you're trying to just wrap the image in a link. If that's correct, what might work as an alternative is adding an onclick to the image itself, and setting a hand cursor. That could create the appearance of the image being a link without you having to care what the parentNode is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜