Tattat
Tattat

Reputation: 15778

How can I know which element fire the event from js?

I have somethings like this:

$('#eventFire').dblclick(function(){ 
         EventHandler.dblclickListener();
});   

I want the EventHandler listen the double click event, and I want the EventHandler know which element from the page is fire this event, how can I do so?

Upvotes: 2

Views: 824

Answers (1)

Nick Craver
Nick Craver

Reputation: 630359

The event object is passed as the first argument to your handler, like this:

$('#eventFire').dblclick(function(e){ 
  //e.target fired the event, this refers to the #eventFire element
});

So inside the handler, the e.target could be the element with the handler or a child (from which the even bubbled), and this will refer to the element the handler is on, #eventFire in this case.

Upvotes: 5

Related Questions