最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to apply a Twitter Bootstrap tooltip to text wrapped in a <span>? - Stack Overflow

programmeradmin1浏览0评论

Apparently you can add a Twitter Bootstrap tooltip to any element that has the .tooltip class, like so:

$(document).ready(function() {
    $("a[rel='tooltip'], .tooltip").tooltip();
});

However, adding this class to a span tag does not seem to work. Example:

<p>1 + 1 = <span class="tooltip" title="Wooo!">2</span></p>

Only links seem to work with tooltips. Example:

<p>2 + 2 = <a href="#" rel="tooltip" title="Wooo!">4</a></p>

Here's a jsFiddle to demonstrate: /

So how can I display a tooltip for text wrapped in a span?

Apparently you can add a Twitter Bootstrap tooltip to any element that has the .tooltip class, like so:

$(document).ready(function() {
    $("a[rel='tooltip'], .tooltip").tooltip();
});

However, adding this class to a span tag does not seem to work. Example:

<p>1 + 1 = <span class="tooltip" title="Wooo!">2</span></p>

Only links seem to work with tooltips. Example:

<p>2 + 2 = <a href="#" rel="tooltip" title="Wooo!">4</a></p>

Here's a jsFiddle to demonstrate: http://jsfiddle/ZznzE/

So how can I display a tooltip for text wrapped in a span?

Share Improve this question edited Jun 27, 2013 at 9:20 XåpplI'-I0llwlg'I - asked Jun 27, 2013 at 9:02 XåpplI'-I0llwlg'I -XåpplI'-I0llwlg'I - 22.5k28 gold badges107 silver badges155 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You don't need a class="tooltip", but a rel="tooltip"

Like this:

<p>1 + 1 = <span rel="tooltip" title="Tip 1">2</span></p>

I updated your fiddle and it works fine now: http://jsfiddle/Xz2e7/1/

I also added a cursor: pointer to the CSS on the span tag. For usability this is better, so people know where there is interaction on the page.

Edit:

The tooltip class is not meant for using like you want to use it. the tooltip class is taking care of the tooltip itself (making it invisible when not hovering for example).

Try this: http://jsfiddle/Xz2e7/3/

发布评论

评论列表(0)

  1. 暂无评论