Skip to content

Instantly share code, notes, and snippets.

@fxbeckers
Created May 2, 2013 14:39
Show Gist options
  • Save fxbeckers/5502657 to your computer and use it in GitHub Desktop.
Save fxbeckers/5502657 to your computer and use it in GitHub Desktop.
Automatically init popovers on click
// jQuery popovers normally have to be initialized on a href with javascript. By hooking in to the click event instead, we can do the same without
// explicitely having to init, which is useful for pages with a dynamic dom
$(document).on('focusin click', '[data-toggle="popover"]', function (e) {
e.preventDefault();
var $element = $(e.target);
if (!$element.has('[data-toggle="popover"]')) {
$element = $element.closest('[data-toggle="popover"]');
}
($element).popover();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment