/ Published in: JavaScript

How to get a reference to the element that was clicked to fire an event. The code is gratefully cribbed from Quirksmode.org.
Updated to reflect how I actually implement this, slightly different from PPK's original.
Expand |
Embed | Plain Text
<html> <head> <script> /* http://quirksmode.org */ function getEvent (e) { var event = e || window.event; if( ! event.target ) { event.target = event.srcElement } return event; } </script> </head> <body> <a href="#fred" id="fred" onclick="alert(getEvent(event).target)">foo</a> </body> </html>
Comments

You need to login to post a comment.
This returns the href value of the tag not the html element tag.
check here
http://tinkerbin.com/IMfx83Su