最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Bootstrap tooltip usage - Stack Overflow

matteradmin5PV0评论

I am adding bootstrap tooltip to my a tag like this :

jQuery('span.arUp a').attr("data-placement", "top");
jQuery('span.arUp a').attr("data-toggle", "tooltip");
jQuery('span.arUp a').attr("data-original-title", "Tooltip on top");

and a tag looks like this :

<a rel="next" href="/?p=28" data-placement="top" data-toggle="tooltip" data-original-title="Tooltip on top">Fedrer</a>

But no tooltip is ing. Please help!!

I am adding bootstrap tooltip to my a tag like this :

jQuery('span.arUp a').attr("data-placement", "top");
jQuery('span.arUp a').attr("data-toggle", "tooltip");
jQuery('span.arUp a').attr("data-original-title", "Tooltip on top");

and a tag looks like this :

<a rel="next" href="http://roadmap.private/?p=28" data-placement="top" data-toggle="tooltip" data-original-title="Tooltip on top">Fedrer</a>

But no tooltip is ing. Please help!!

Share Improve this question edited May 20, 2013 at 17:47 William Buttlicker asked May 20, 2013 at 17:47 William ButtlickerWilliam Buttlicker 6,0005 gold badges35 silver badges58 bronze badges 2
  • Duplicate of stackoverflow./questions/9446318/… – Carol Skelly Commented May 20, 2013 at 18:01
  • @Skelly It doesn't appear to be a duplicate. Sankalp, is the above HTML the output after the jQuery has run, or is the HTML delivered to the browser as you have written it? – seangates Commented May 20, 2013 at 18:09
Add a ment  | 

3 Answers 3

Reset to default 3

Bootstrap tooltip usage:

<a rel="next" href="http://roadmap.private/?p=28" title="Tooltip on top">Fedrer</a>

$(function(){
    $('span.arUp a').tooltip({
        placement: 'top'
    });
});

and make sure you include the bootstrap js file.

Since you are using the data-*, you are using the auto mode of the tooltip, which it automatically adds itself to the elements it finds.

Since you are adding the data-* with JS instead of directly into the HTML, you need:

  • Add the .js file AFTER your additions

or

  • Call $('span.arUp a').tooltip after your code.

If you need the tooltip feature to work with dynamic elements, you can try this:

$(document).ready(function () {
    $("body").tooltip({
        selector: '[data-toggle="tooltip"]'
    });
});

DEMO: http://jsfiddle/FHjVs/1/

Then, whenever an element has an attribute data-toggle="tooltip", a tooltip will be applied, without having to run JavaScript/jQuery code.

Reference:

  • How do I bind Twitter Bootstrap tooltips to dynamically created elements?
Post a comment

comment list (0)

  1. No comments so far