Abel Tamayo schrieb:
> Hi all. I'd like to know if there's a standard, easy way to determine
> with element triggered an event. I'm pretty sure there is, but can't
> find it in google. Maybe an atribute in the e parameter received by
> the function like:
>
> $("p").bind(
> "click",
> function(e){
> console.log(e.TRIGGER); // This trigger attribute of the element e
> is the one that started the action.
> }
> );
Inside the event handler, the "this"-keyword refers to the element that
handles the event, while the "target" property of the event object
refers to the element that triggered the event.
$("p").click(function(event) {
alert(this) // <- always refers to a paragraph
alert(event.target) // <- refers to a paragraph or any child of it
});
You can use the target property to implement a event delegation (instead
of event handling). A plugin that uses that:
http://bassistance.de/jquery-plugins/jquery-plugin-accordion/
Of course it has its drawbacks, as discovered recently, see the comments
at the end of that page.
--
Jörn Zaefferer
http://bassistance.de
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/