Created
September 19, 2012 07:04
-
-
Save martinnormark/3748101 to your computer and use it in GitHub Desktop.
jQuery plug-in for removing a DOM element, when clicking outside it
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
(function ($) { | |
$.fn.clickOutsideToRemove = function () { | |
return this.each(function () { | |
var $this = $(this); | |
$(document).on("mouseup.clickOutsideToRemove", function (e) { | |
if ($this.has(e.target).length === 0) { | |
$this.remove(); | |
$(document).off(".clickOutsideToRemove"); | |
} | |
}); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment