Can we get popovers to be dismissable in the same way as modals, ie. make them close when user clicks somewhere outside of them?
Unfortunately I can't just use real modal instead of popover, because modal means position:fixed and that would be no popover anymore. :(
Modified accepted solution. What I've experienced was that after some popovers were hidden, they would have to be clicked twice to show up again. Here's what I did to ensure that popover('hide') wasn't being called on already hidden popovers.
Most simple, most fail safe version, works with any bootstrap version.
Demo: http://jsfiddle.net/guya/24mmM/
Demo 2: Not dismissing when clicking inside the popover content http://jsfiddle.net/guya/fjZja/
Demo 3: Multiple popovers: http://jsfiddle.net/guya/6YCjW/
Simply calling this line will dismiss all popovers:
Dismiss all popovers when clicking outside with this code:
The snippet above attach a click event on the body. When the user click on a popover, it'll behave as normal. When the user click on something that is not a popover it'll close all popovers.
It'll also work with popovers that are initiated with Javascript, as opposed to some other examples that will not work. (see the demo)
If you don't want to dismiss when clicking inside the popover content, use this code (see link to 2nd demo):
I was having issues with mattdlockyer's solution because I was setting up popover links dynamically using code like this:
So I had to modify it like so. It fixed a lot of issues for me:
Remember that destroy gets rid of the element, so the selector part is important on initializing the popovers.
simply add this attribute with the element
This is late to the party... but I thought I'd share it. I love the popover but it has so little built-in functionality. I wrote a bootstrap extension .bubble() that is everything I'd like popover to be. Four ways to dismiss. Click outside, toggle on the link, click the X, and hit escape.
It positions automatically so it never goes off the page.
https://github.com/Itumac/bootstrap-bubble
This is not a gratuitous self promo...I've grabbed other people's code so many times in my life, I wanted to offer my own efforts. Give it a whirl and see if it works for you.