Skip to content

Instantly share code, notes, and snippets.

@sbrin
Last active October 25, 2016 19:59
Show Gist options
  • Save sbrin/5dcc616fbfbd5f980ae1dfceb40203c7 to your computer and use it in GitHub Desktop.
Save sbrin/5dcc616fbfbd5f980ae1dfceb40203c7 to your computer and use it in GitHub Desktop.
jQuery simple popover hides on click anywhere beside itself
$(function () {
var pop = {};
pop.shown = false;
pop.item = $('.popover');
$('body').on('click', function(e){
if ( e.target.className == 'button-block' ){
if ( pop.shown == true ){
pop.item.hide();
pop.shown = false;
} else if ( pop.shown == false ) {
pop.item.show();
pop.shown = true;
}
} else if ( e.target.className != 'popover-content' ){
if ( pop.shown == true ){
pop.item.hide();
pop.shown = false;
}
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment