I use the code as follows:
$(\".reply\").popover({
content: \"Loading...\",
placement: \"bottom\"
});
$(\".reply\").popover(\"toggle\");
This answer from 2012 does not work with Bootstrap 3 popovers. I extracted a working solution from this question:
$("#popover").attr('data-content', 'new content');
If you grab the popover instance like this:
var popover = $('.reply').data('bs.popover');
Then, to redraw the popover, use the .setContent()
method:
popover.setContent();
I found out browsing the source: https://github.com/twitter/bootstrap/blob/master/js/popover.js
So, in your example, try:
thisVal.attr('data-content',data).data('bs.popover').setContent();
Update
The setContent()
method also removes the placement class, so you should do:
var popover = thisVal.attr('data-content',data).data('bs.popover');
popover.setContent();
popover.$tip.addClass(popover.options.placement);
Demo: http://jsfiddle.net/44RvK
SIMPLE SOLUTION
You can try with this :
//Bootstrap v3.3.7
var popoverEl = $("#popover");
popoverEl.attr("data-content", "NEW CONTENT");
popoverEl.popover("show");
Thanks.
you can just pass the title as function
var content = 'Loading...'
function dynamicContent(){
return content
}
$(".reply").popover({
content: dynamicContent,
placement: "bottom"
});
$(".reply").popover("toggle");
and then change the variable content dynamically.
When a popover is enabled, it retains its previous version(if it was created already) even if the data is change. You need to destroy the previous version to allow for the new popover to be created again. In Bootstrap 4.x do it by
.popover('dispose')
do it whenever there is a change in data through an ajax call.
In bootstrap 3:
if($el.data('bs.popover')) {
$el.data('bs.popover').options.content = "New text";
}
$el.popover('show');