I've got a few DOM elements, say text-field input A, B, C, and all of them have the property of 'onclick'. How do I find to which object a particular 'onclick' belongs?
yes! I'm trying to find the element that triggered an event handler. I actually tried this, but it returns undefined. here's my code:var oc_property = document.forms[0].realname.onclick;console.log("onclick's element: " + oc_property.this);
Paul
2010-05-23 02:26:30
You're doing it wrong. **Very** wrong.
SLaks
2010-05-23 02:27:03
Ha, ha, clueless. Also, jQuery? Ugh. :P
Delan Azabani
2010-05-23 02:34:39
@Delan: What?
SLaks
2010-05-23 02:36:03
Hi SLaks, how to find the element if I use addEventListener like the following:document.forms[0].realname.addEventListener('click', hello, true);
Paul
2010-05-23 02:47:28
You can add separate, identical functions (or wrapper functions) and make a property on each function object. Note that if you set the property to the DOM element, you'll get a memory leak in IE6. Use its name or ID instead.
SLaks
2010-05-23 02:48:24
@SLaks: read this: http://azabani.com/51
Delan Azabani
2010-05-23 07:55:10