jquery delegate passing variable
I want to pass the object of being clicked into the handler. like this:
$selector.dele开发者_StackOverflow社区gate('.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.
Try this
$selector.delegate('.test','click', function(e){
var obj = this;
//obj will point to the element you clicked.
});
Use $(this)
inside func1
. this
will be the object on which the event occurred.
精彩评论