Bootstrap popover content cannot changed dynamically

后端 未结 14 2266
旧时难觅i
旧时难觅i 2020-11-29 22:40

I use the code as follows:

$(\".reply\").popover({
  content: \"Loading...\",
  placement: \"bottom\"
});

$(\".reply\").popover(\"toggle\");
14条回答
  •  死守一世寂寞
    2020-11-29 23:15

    Yes you can, in fact the easiest way haven't been suggested yet.

    Here's my way ->

        var popover = $('#example').data('bs.popover');
        popover.options.content = "YOUR NEW TEXT";
    

    popover is an object if you want to know more about it, try to do console.log(popover) after you define it to see how you can use it after !

    EDIT

    As of Bootstrap 4 alpha 5, the data structure is a bit different. You'll need to use popover.config.content instead of popover.options.content

    Thanks to @kfriend for the comment

提交回复
热议问题