开发者

jquery delegate passing variable

开发者 https://www.devze.com 2023-03-21 01:06 出处:网络
I want to pass the object of being clicked into the handler. like this: $selector.dele开发者_StackOverflow社区gate(\'.test\',\'click\',func1( ?? ));

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消