bingjie2680
bingjie2680

Reputation: 7773

jquery delegate passing variable

I want to pass the object of being clicked into the handler. like this:

$selector.delegate('.test','click',func1( ?? ));

//this is a reusable function
function func1(obj){
    //do something with obj  .....
}

so in this case, I should pass $('.test') into the function. can anybody give me a hand here, thanks a lot.

Upvotes: 2

Views: 2184

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this

$selector.delegate('.test','click', function(e){
var obj =  this;
//obj will point to the element you clicked.
});

Upvotes: 3

Dark Falcon
Dark Falcon

Reputation: 44181

Use $(this) inside func1. this will be the object on which the event occurred.

Upvotes: 2

Related Questions