jquery - Exclude click event based on condition? -
i'm trying set conditions on jquery event. have input element , div. want detect click anywhere on page , execute method if click not on input or div.
use jquery click() or live() functions , check target of click event using jquery is() function.
- bind click event on document
- if target not input or div continue
.
$(document.body).click(function(e) { if( !$(e.target).is("input, div") ) { console.log("run function because image or div not clicked!"); } });
example webpage => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-document-click-exclusion.html
example firebug output after clicking around on example page
Comments
Post a Comment