views:

45

answers:

1

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?

+2  A: 
SLaks
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
You're doing it wrong. **Very** wrong.
SLaks
Ha, ha, clueless. Also, jQuery? Ugh. :P
Delan Azabani
@Delan:‌‌‌‍‌‍‌‍‌‍ ‌‍‌‍‌‍‌‍‌‍‌‍What?
SLaks
Hi SLaks, how to find the element if I use addEventListener like the following:document.forms[0].realname.addEventListener('click', hello, true);
Paul
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
@SLaks: read this: http://azabani.com/51
Delan Azabani