Can't change bootstrap Tooltip title

2020-03-19 03:08发布

I've already looked over several posts on stack overflow asking virtually the exact same question yet none of what I found on those questions has helped. I'm very new to JQuery and Bootstrap so maybe I'm just missing some really simple thing.

I want to be able to to change the title of the tooltip on different elements after the first initialization(ideally multiple times after initialization.) A simplified version of what I'm dealing with:

<canvas id="bag0"  data-toggle="tooltip" title="test">
</canvas>
...
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

$(document).ready(function(){
            $('#bag0').data('tooltip',false)          
                  .tooltip({ title: 'new text'});
            $('[data-toggle="tooltip"]').tooltip();

});

This method to change the title was given from posting: How to overwrite twitter bootstrap tooltip?

The tooltip always reads "test." I've tinkered with a few others things to no avail. I suspect I'm overlooking something obvious.

7条回答
仙女界的扛把子
2楼-- · 2020-03-19 03:51

I may be a bit too late but my solution to this was to change the data-original-title

$('.sample').attr('data-original-title': 'new title');

This changes the bootstrap tool tip title automatically.

查看更多
登录 后发表回答