Last active
April 13, 2018 15:41
-
-
Save MSerj/54319b4e75a026e2fb159d8ee9e61adf to your computer and use it in GitHub Desktop.
close div by click outside
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
$(document).mouseup(function (e) { | |
var container = $("YOUR CONTAINER SELECTOR"); | |
if (!$(e.target).closest(container).length){ | |
container.hide(); | |
} | |
}); | |
//что означает следующее - если клик был по области, которая НЕ является нашим div'ом или не содержится в нем, то скрыть блок. | |
//Это решает проблему, если клик был по элементу вложенному в блок (не по самому блоку). Элемент будет скрыт, только если клик по области ВНЕ div'a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment