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

javascript, jquery, twitter-bootstrap

Solution

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')

Problem

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"); }); ```

Original source