Last active
December 28, 2015 05:29
-
-
Save argshook/7450179 to your computer and use it in GitHub Desktop.
Click outside the element to hide it. I was always having difficulties with this, here's a nice tip.
This depends on jQuery, just follow the same logic for any other framework or even vanilla JS.
This file contains hidden or 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
// change selectors as you need | |
var selector = '.selector'; | |
$(document).ready(function() { | |
$(selector).click(function(e) { | |
$(selector).show(); | |
e.stopPropagation(); | |
}); | |
$('body').click(function(e) { | |
if($(e.target).closest(selector).get(0) == null ) { | |
$(selector).hide(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment