Do something when user click somewhere outside of wrapper

To close or do something when users clicks outside of some element following few lines of code can be helpful.

$(document).click(function(event) {
	if ($(event.target).parents().index($('#first_wrapper')) == -1 &&
		$(event.target).parents().index($('.second_wrapper')) == -1) {
		// Run something
	}
});

Posted

in

,

by

Comments

Leave a Reply