开发者

Is there a way to remove all namespaced binds in jQuery?

I have some simple code like:

$('#modal-buttons [href*=close]').bind('click.modalClose',function(){
  app().modal('close')
});

But let's say I wont know everywhere the click.modalClose will be bound, is there a way to destroy all of those specific binds no matter what the element rather than having to do the fo开发者_运维知识库llowing?

$('#modal-buttons [href*=close],.someOtherelement,#onemore,.another').unbind('click.modalClose');


To get rid of all bindings, just do:

$('*').unbind('click.modalClose');

That'll get all of them. Alternatively, you could make sure that the binding always happens via your own API, and then you can keep track of what elements are actually affected. (If you're going to unbind the handlers from all elements they're bound to, however, I don't see the point, unless your page is of epic proportions and the $('*') thing takes too long.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜