开发者

Jquery: using not to exclude certain elements from click event?

$(top.document).ready(function () {   

   $(document).not('#开发者_运维问答mymenu *').click(processAction);

});

function processAction();

this doesn't seem to be working. any suggestions ?


I wouldn't try binding to every element on the page -- very expensive and inefficient. I would use $().delegate:

$(document).ready(function() {
    $('body').delegate(':not(#mymenu *, #mymenu)','click', processAction);
});

This binds the event to the body. When a anything is clicked, the event bubbles up the DOM tree and is captured with this handler. If the original DOM element matches the selector, the function is called. This means only one bind, rather than potentially dozens.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜