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