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.

  1. bind click event on document
  2. 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

alt text


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -