Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the current state of a twitter bootstrap popover?

I currently call a script to dynamically add content to my popover but I don't need to make this call when a user clicks again to close it. Is it possible to get the state and close it when it's visible?

This is what I have so far:

$('.knownissue').on('click', function() {

    var info = $(this).attr('id').substr(5).split(':');
    var el = $(this);

    // How do I check to see if the popover is visible
    // so I can simply close it and exit?

    $.post('functions/get_known_issues.php?tcid='+info[0]+'&tcdate=' + info[1], function(data) {
        if (data.st) {
            el.attr('data-content', data.issue);
            el.popover('toggle');
        }
    }, "json");

});
like image 240
user1216398 Avatar asked Nov 01 '12 19:11

user1216398


People also ask

How do I know if bootstrap popover is open?

You can also check using a condition $('#anElement'). next(). hasClass('popover') which will return true if the popover is on.

How do I customize bootstrap popover?

To create a popover, you need to add the data-bs-toggle="popover" attribute to an element. Whereas, popover's title and its content that would display upon trigger or activation can be specified using the title and data-bs-content attribute respectively. Here is the standard markup for adding a popover to a button.

How do I use bootstrap popover?

How To Create a Popover. To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.


2 Answers

To avoid searching for dynamically inserted markup you can do this:

In Bootstrap 2:

var $element = $('.element-you-added-popup-to')
$element.data().popover.tip().hasClass('in')
// Or if you used '.tooltip()' instead of '.popover()'
$element.data().tooltip.tip().hasClass('in')

In Bootstrap 3:

$element.data()['bs.popover'].tip().hasClass('in')
$element.data()['bs.tooltip'].tip().hasClass('in')
like image 80
Will Madden Avatar answered Sep 22 '22 22:09

Will Madden


if($('.popover').hasClass('in')){
  // popover is visable
} else {
  // popover is not visable
}
like image 33
Yohn Avatar answered Sep 23 '22 22:09

Yohn