开发者

jQuery Not Selector and Live Binding

I am trying to bind all of the a elements on a page except for those with the title attribute of on. The code below ends up not attaching the click event to any of the a elements on the page. If I remove the not it works but of course binds to a elements I do n开发者_JS百科ot want the code applied to. What am I doing wrong with the not selector?

$(document).ready(function() {
     $('a').not('title=on').live('click', function(event) { ... });
});


An valid option would be

$(document).ready(function() {
     $('a:not([title=on])').live('click', function(event) { ... });
});

Here you have another option

$(document).ready(function() {
     $('a[title!=on]').live('click', function(event) { ... });
});


From the docs:

DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector.

I had the same issue, and stumbled across this info here: http://bugs.jquery.com/ticket/8378


$('a:not[title=on]').live('click', function(event){...});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜