How to update bootstrap popover text?

后端 未结 9 839
长发绾君心
长发绾君心 2020-12-07 20:31

I am using bootstrap-popover to show a message beside an element.

If I want to show different text in the popover after the first time, the text does not change. Re

9条回答
  •  感情败类
    2020-12-07 20:34

    The question is more than one year old, but maybe this would be usefull for others.

    If the content is only changed while the popover is hidden, the easiest way I've found is using a function and a bit of JS code.

    Specifically, my HTML looks like:

    
    
    

    Please note no data-content is specified. In JS, when the popover is created, a function is used for the content:

    $('test').popover({
        html: true,
        content: function() { return $('#popover-content').html(); }
    });
    

    And now you can change anywhere the popover-content div and the popover will be updated the next time is shown:

    $('#popover-content').html("

    New content

    ");

    I guess this idea will also work using plain text instead of HTML.

提交回复
热议问题