Back in Bootstrap 4.0, you could easily change the popover content dynamically based on the selector
or reposition it using the $tip
property.
$("body").popover({
container: 'body',
content: 'loading...',
html: true,
placement: 'right',
trigger: "hover",
selector: '.selector1', '.selector2', ...
}).on('shown.bs.popover', function () {
var this = $(event.target);
...
if (this.hasClass('.selector1')) {
var popover_method = ".../dynamic_popover_1"
}
...
$.get(popover_method, {
...
},
function(response) {
var popover_tip = $(this.data('bs.popover').tip);
popover_tip.find('.popover-body').empty().append(response.popover_data_json);
if ((popover_tip.offset().top - $(window).scrollTop()) + popover_tip.height() > window.innerHeight) {
popover_tip.css({ top: - popover_tip.height() + 5 });
}
...
However, in Bootstrap 5.0, the data('bs.popover')
method no longer exists. So, how can you achieve the same functionality in Bootstrap 5.0?