Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:09:47+00:00 2026-05-28T14:09:47+00:00

I’m currently using popovers with Twitter Bootstrap, initiated like this: $(‘.popup-marker’).popover({ html: true, trigger:

  • 0

I’m currently using popovers with Twitter Bootstrap, initiated like this:

$('.popup-marker').popover({
        html: true,
        trigger: 'manual'
    }).click(function(e) {
        $(this).popover('toggle');
        e.preventDefault();
    });

As you can see, they’re triggered manually, and clicking on .popup-marker (which is a div with a background image) toggles a popover. This works great, but I’d like to also be able to close the popover with a click anywhere else on the page (but not on the popover itself!).

I’ve tried a few different things, including the following, but with no results to show for it:

$('body').click(function(e) {
    $('.popup-marker').popover('hide');
});

How can I close the popover with a click anywhere else on the page, but not with a click onthe popover itself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:09:48+00:00Added an answer on May 28, 2026 at 2:09 pm

    Presuming that only one popover can be visible at any time, you can use a set of flags to mark when there’s a popover visible, and only then hide them.

    If you set the event listener on the document body, it will trigger when you click the element marked with ‘popup-marker’. So you’ll have to call stopPropagation() on the event object. And apply the same trick when clicking on the popover itself.

    Below is a working JavaScript code that does this. It uses jQuery >= 1.7

    jQuery(function() {
        var isVisible = false;
    
        var hideAllPopovers = function() {
           $('.popup-marker').each(function() {
                $(this).popover('hide');
            });  
        };
    
        $('.popup-marker').popover({
            html: true,
            trigger: 'manual'
        }).on('click', function(e) {
            // if any other popovers are visible, hide them
            if(isVisible) {
                hideAllPopovers();
            }
    
            $(this).popover('show');
    
            // handle clicking on the popover itself
            $('.popover').off('click').on('click', function(e) {
                e.stopPropagation(); // prevent event for bubbling up => will not get caught with document.onclick
            });
    
            isVisible = true;
            e.stopPropagation();
        });
    
    
        $(document).on('click', function(e) {
            hideAllPopovers();
            isVisible = false;
        });
    });
    

    http://jsfiddle.net/AFffL/539/

    The only caveat is that you won’t be able to open 2 popovers at the same time. But I think that would be confusing for the user, anyway 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.