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
})
精彩评论