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.
精彩评论