Skip to content

Instantly share code, notes, and snippets.

@EnzoEmb
Created April 30, 2019 15:45
Show Gist options
  • Save EnzoEmb/df3cb4b670b5fedfad08a5166a456d85 to your computer and use it in GitHub Desktop.
Save EnzoEmb/df3cb4b670b5fedfad08a5166a456d85 to your computer and use it in GitHub Desktop.
outside click jquery
(function($){
$.fn.outside = function(ename, cb){
return this.each(function(){
var $this = $(this),
self = this;
$(document.body).bind(ename, function tempo(e){
if(e.target !== self && !$.contains(self, e.target)){
cb.apply(self, [e]);
if(!self.parentNode) $(document.body).unbind(ename, tempo);
}
});
});
};
}(jQuery));
$('.selector-dropdown').outside('click', function(e) {
$('.selector.active').removeClass('active');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment