开发者

jquery live context

开发者 https://www.devze.com 2023-03-03 17:59 出处:网络
I\'d like to do a live function on 开发者_JAVA技巧a selector, but i want to add a context depending on this selector.

I'd like to do a live function on 开发者_JAVA技巧a selector, but i want to add a context depending on this selector. I know that's wrong but what could be correct to make that right:

$('.myClass',$(this).parent()).live('myEvent',function(){..})

.myClass is a duplicated element class. And this 'live' make me possible to limit the event only in the context, in fact selector parent. I hope I'm understandable.


It looks like what you're looking for is the .delegate() function, which is just like .live(), but allows for a context (sort of), along with other benefits.

Try this code:

$(this).parent().delegate('.myClass','myEvent',function() { .. } );


Try this

$(document).on(".myClass","event",function(){
   var select = $(this).parent();
   //use select for further implentation as selecter
})
0

精彩评论

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