tags:

views:

31

answers:

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

   $(document).not('#mymenu *').click(processAction);

});

function processAction();

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

+1  A: 

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.

lonesomeday
works great ! thank you. will accept your answer in 3 minutes.
Kim Jong Woo
this seems to completely ignore teh not phrase on mymenu
Kim Jong Woo
I haven't got time to construct a test now, but you might try ':not(#mymenu > *)' instead. The other option is to match everything in the delegate handler ('*') and check using $(this).parents('#mymenu') at the beginning of the processAction function. This isn't the best way to do it (inefficient) but would work.
lonesomeday
Ah, the problem is that the ':not(#mymenu *)' selector does not exclude #mymenu itself. I will update the answer to correct this.
lonesomeday