Vimalan Jaya Ganesh Vimalan Jaya Ganesh - 9 months ago 69
Javascript Question

Dynamically change content of popover in bootstrap

I am trying to change the content of bootstrap popover dynamically but it is not working.


<button class="btn btn-danger btn-xs" id="SaveChangesBtn" type="button" data-toggle="popover" data-trigger="manual" data-content="There are no changes to save."><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>&nbspSave Changes</button>


$('#SaveChangesBtn').on('click', function(){
$(this).popover({content: 'Cannot proceed with Save while Editing a row.'}).popover('show');

Current Result:

When Save changes button is clicked, the content 'There are no changes to save' is displayed.


The dynamic content "Cannot proceed with Save while Editing a row." should be displayed.

Any help is appreciated.

Answer Source

You can try something like this:

$('#SaveChangesBtn').on('click', function(){
    $(this).attr('data-content','Cannot proceed with Save while Editing a row.');

This way you fix the way you are showing and hiding your popover.

Working fiddle: