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");
});
You can also check using a condition $('#anElement'). next(). hasClass('popover') which will return true if the popover is on.
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 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.
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')
if($('.popover').hasClass('in')){
// popover is visable
} else {
// popover is not visable
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With