Changing content in a Bootstrap popover

It would seem like you should be able to dynamically change the content of a popover in Bootstrap just by doing the following:

$("#someElement").popover({content: "New content here"});

But that syntax can only be used for initialization of a popover. After much searching, I finally found an answer on Stack Overflow that allows the popover content to be changed whenever.  Also, see this working demo by the same person who posted the answer on Stack Overflow.  Here’s the code:

$('#someElement').attr('data-content', 'New content here');
var popover = $('#someElement').data('popover');
$('#someElement').popover('show'); //Shows popover with new content!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: