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</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:
The reason is that when using
href="javascript:...,thisdoesn’t refer to the element that received the event.You need to be in an event handler like
onclickfor that.