jQuery bind click *ANYTHING* but *ELEMENT* -
jQuery bind click *ANYTHING* but *ELEMENT* -
say there elements floating around, , i'm trying when click anything(divs, body, whatever...) 1 specified (e.g. div#special).
i'm wondering if there's improve way accomplish besides next method can think of...
$(document).bind('click', function(e) { mouse position x, y element (div#special in case) position x, y element width , height determine if mouse within element if(inside) nil else });
to handle "do except when this element clicked" situation, general approach add together event handler document handles "do this" case, add together event handler "except this" element, prevents click event bubbling document;
$('#special').on('click', function(e) { e.stoppropagation(); }); $(document).on('click', function (e) { // whatever want; event that'd fire if "special" element has been clicked on has been cancelled. }); see the event.stoppropagation() documentation. of using versions before jquery 1.7 (as case when question asked), won't able utilize on(); instead simple replace 2 uses of on() bind(); signature in case same.
demo here; http://jsfiddle.net/hbbvc/
jquery click
Comments
Post a Comment