2

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how can I get back the #eventFire from the e??
@Tattat - Just use e.target, it'll be a DOM element...but it sounds like you don't want the target, you want the element you're binding to, and use this for that...it'll be the DOM element, use $(this) for a jQuery object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.