question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using multiple HTML tooltips always returns the first tooltipster occurence

See original GitHub issue

I’ve been trying for two days to figure out how to use HTML inside mutiple non-cloned tooltips as suggested in the Tooltipster homepage. The issue I run into is:

When using detach() with multiple tooltips, it (i) always returns the first occurrence and (ii) there is an additionnal glitch: the content display the first occurence then blinks and disappears when hovering on other tooltips. For example, using:

$(document).ready(function() {
            $('.tooltip').tooltipster({
            contentAsHTML: true,
                        content: $('#tooltip_content').detach(),
            contentCloning: false
            });
        });

and:

<img src="Pics/Front.png" alt="Front" border="1" class="tooltip" />
<span id="tooltip_content"> toto </span>
<img src="Pics/Far.png" alt="Far" border="1" class="tooltip"/>
<span id="tooltip_content"> titi </span>
<img src="Pics/Side.png" alt="Side" border="1" class="tooltip"/>
<span id="tooltip_content"> tutu </span>

will always returns ‘toto’ no matter the <img> we’re hovering over. And it also produces the above mentionned glitch with a empty tooltip when hovering out the img.

I tried another approach in directly altering the ‘content’ using $(this). However, it also returns ‘toto’. For example:

$(document).ready(function() {
            $('.tooltip').tooltipster({
            contentAsHTML: true,
            content: $(this).find('.tooltip').attr('alt'),
            contentCloning: false
            });
        });

and:

<img src="Pics/Front.png" alt="Front" border="1" class="tooltip" />
<img src="Pics/Far.png" alt="Far" border="1" class="tooltip"/>
<img src="Pics/Side.png" alt="Side" border="1" class="tooltip"/>

Will always return ‘Front’ (without the glitch this time). I also tried: content: $(this).attr('alt'), but it returns an ‘undefined’ string instead.

Thus my question is: how to succeed in using mutiple HTML tooltips in the same HTML page ? I’d prefer to avoid the encoded markup in the title attribute.

Thank you

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
louisamelinecommented, Jul 14, 2016

That’s because of the structure of your HTML. I overlooked the fact that you were putting tooltips on images. So try something like this instead:

<img id="tooltip_1" src="Pics/Front.png" alt="Front" border="1" class="tooltip" />
<div id="tooltip_1_content">This is tooltip 1</div>
<img id="tooltip_2" src="Pics/Far.png" alt="Far" border="1" class="tooltip"/>
<div id="tooltip_2_content">This is tooltip 2</div>
<img id="tooltip_3" src="Pics/Side.png" alt="Side" border="1" class="tooltip"/>
<div id="tooltip_3_content">This is tooltip 3</div>
$('.tooltip').tooltipster({
    theme: 'tooltipster-noir',
    animation: 'slide',
    delay: 100,
    functionInit: function(instance, helper){
        var id = $(helper.origin).attr('id'),
            content = $('#' + id + '_content').detach();
        instance.content(content);
    }
});
0reactions
louisamelinecommented, Jul 14, 2016

You’re welcome. Je t’en prie 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - tooltipster - using one function on multiple tooltips
I'm using a combination of Mark.js and Tooltipster to display some content. Mark.js appends a class (or multiple classes) to a specific string ......
Read more >
Tooltipster - The jQuery Tooltip Plugin
Tooltipster is a powerful, flexible jQuery plugin enabling you to easily create clean, HTML5 validated tooltips.
Read more >
Tooltipster - The jQuery Tooltip Plugin - GitHub Pages
Tooltipster allows you to use any HTML markup inside your tooltips. ... the selector matches multiple origins, only the value of the first...
Read more >
Multiple Tooltips Cause Blank Contents · Issue #570 - GitHub
When I create multiple tooltips with the same content, only the last one has the content and ... http://iamceege.github.io/tooltipster/#html ...
Read more >
Bootstrap Tooltip Plugin - W3Schools
Tip: Plugins can be included individually (using Bootstrap's individual "tooltip.js" file), or all at once (using "bootstrap.js" or "bootstrap.min.js").
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found