Created
April 30, 2019 15:45
-
-
Save EnzoEmb/df3cb4b670b5fedfad08a5166a456d85 to your computer and use it in GitHub Desktop.
outside click jquery
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.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