DanWebb
2/17/2015 - 9:07 AM

perform an action when clicking anywhere *but* an element on the page

perform an action when clicking anywhere but an element on the page

$doc.on('click', function(e) {
  // if the element clicked is not the *but element* or a child of the *but element*
  if(
    !$(e.target).parents('.but-element').length &&
    !$(e.target).hasClass('but-element')
  ) {
    // your code here
  }
});