admin管理员组文章数量:1398999
I tried to change the tooltip placement dynamically but it does not work.
<input type="text" id="sample" title="Tip">
<button name="change me" id="changeBtn">Change Tool Tip!</button>
And for js:
//Initiall tooltip for all elements
$("[title!='']").tooltip();
$("#changeBtn").click(function () {
//Change tooltip placment
$("#sample").tooltip({placement : 'left'}).tooltip('show');
})
/
I found a good answer at Change Twitter Bootstrap Tooltip content on click which shows how to change tooltip text dynamically by using tooltip('fixTitle')
method. But could not find something for placement.
I tried to change the tooltip placement dynamically but it does not work.
<input type="text" id="sample" title="Tip">
<button name="change me" id="changeBtn">Change Tool Tip!</button>
And for js:
//Initiall tooltip for all elements
$("[title!='']").tooltip();
$("#changeBtn").click(function () {
//Change tooltip placment
$("#sample").tooltip({placement : 'left'}).tooltip('show');
})
http://jsfiddle/znvv9ar5/
I found a good answer at Change Twitter Bootstrap Tooltip content on click which shows how to change tooltip text dynamically by using tooltip('fixTitle')
method. But could not find something for placement.
3 Answers
Reset to default 8In Bootstrap 2.x, the answer is:
$('#sample').data('tooltip').options.placement = 'right';
However, from Bootstrap 3, all Bootstrap data is namespaced with bs:
$('#sample').data('bs.tooltip').options.placement = 'right';
Code:
$("#changeBtn").click(function () {
$('#sample').data('tooltip').options.placement = 'left';
$("#sample").tooltip('show');
});
Play it here
Try using "destroy" on the tooltip and bind it again
$("#sample").tooltip("destroy").tooltip({placement : 'left'}).tooltip('show');
Although I do not like using !important it does help to cheat a little in this case.
.tooltip {
left: 12px!important;
}
http://jsfiddle/znvv9ar5/1/ as a result.
You can apply this CSS with the on click.
本文标签: javascriptDynamically change bootstrap tooltip placementStack Overflow
版权声明:本文标题:javascript - Dynamically change bootstrap tooltip placement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744141092a2592624.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论