开发者

Access Parent Element Within href

So... this is a simple question with a simple answer, but somehow my RTFMing isn't proving any results.

I have a link within a div, like so:

<div> <a href=''>Close&开发者_开发技巧lt;/a>

I'd like to close that div with that link, and I've been trying the following code:

<div> <a href="javascript:this.parentNode.style.display='none'">Close</a>

However, it still hasn't worked... any suggestions are greatly appreciated.


Change it to this:

<div> <a href="#" onclick="this.parentNode.style.display='none'">Close</a>

The reason is that when using href="javascript:..., this doesn't refer to the element that received the event.

You need to be in an event handler like onclick for that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜