Created
April 8, 2016 09:44
-
-
Save ariona/c8617a2d07623e8c53dcf0d333694f8e to your computer and use it in GitHub Desktop.
Simulate Click Outside 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
$.fn.clickOff = function(callback, selfDestroy) { | |
var clicked = false; | |
var parent = this; | |
var destroy = selfDestroy || true; | |
parent.click(function() { | |
clicked = true; | |
}); | |
$(document).click(function(event) { | |
if (!clicked) { | |
callback(parent, event); | |
} | |
if (destroy) { | |
//parent.clickOff = function() {}; | |
//parent.off("click"); | |
//$(document).off("click"); | |
//parent.off("clickOff"); | |
}; | |
clicked = false; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment