Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery focusOut except if

I simply want to hide a div, if a text box loses focus, unless, the user clicks in another certain div. If user clicks that particular div, then the focusout doesn't trigger the div.box being hidden.

Below is code with my pseudocode commenting. Any ideas?

textInput.focusout(function() {
    // So long you didn't click div.stop, then
        $('div.box').hide();
});
like image 747
James Avatar asked Jan 22 '23 09:01

James


1 Answers

$(document).bind('click',function(e) {
  if ($(e.target).closest('div.box').length) return;
  $('div.box').hide();
});

Try this!

like image 130
vuong Avatar answered Feb 03 '23 17:02

vuong