user888750
user888750

Reputation:

How to reference $(this) when using on()

I'm using on() to mimic live() and can't for the life of me figure out how to properly reference $(this) so it references the selector I passed in. Here's the code, $(this) returns "body" instead of "select".

$("body").on("change", "select", function(e){
    console.log($(this));
});

Upvotes: 1

Views: 65

Answers (2)

Adil
Adil

Reputation: 148130

You can use event.target to the the source of event.

Live Demo

$("body").on("change", "select", function(e){
    console.log($(e.target));
});

Upvotes: 1

Gats
Gats

Reputation: 3462

try this

$(e.currentTarget);

e is actually the event arguments for the event and that's what you want I beleive.

Upvotes: 2

Related Questions