Created
March 18, 2015 15:29
-
-
Save lewiswalsh/c491a059800d18f0e811 to your computer and use it in GitHub Desktop.
jQuery: Hide on click outside of element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('mouseup', function(e){ | |
var my_element = $('<my_element_selector>'); | |
if( | |
!my_element.is(e.target) // if the target of the click isn't the live_search_results... | |
&& my_element.has(e.target).length === 0 // ...nor a descendant of the live_search_results | |
&& my_element.is(":visible") // Is it even showing on screen? | |
){ my_element.slideUp(); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment