mok_ku
mok_ku

Reputation: 236

jQuery, use event.target inside .on()

I have a function that looks like this:

function preview(obj){
  ...
}

and here is how I call the function,

$('.parent').on('click','.child',preview);

The problem is how to I define the "obj", I tried the following code, but no luck.

$('.parent').on('click','.child',{obj:event.target},preview);

Or the only way I can use is like this, which I tried and work as expected.

$('.parent').on('click','.child',function(){
  preview($(this));
});

Upvotes: 0

Views: 38

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Try like this

$('.parent').on('click','.child',function(event){
  preview(event.target);
});

Upvotes: 1

Related Questions