JavaEar 专注于收集分享传播有价值的技术资料

Change content of tooltipster on initialize

I have too many link on a page having tooltip, I want to set content of every link's tooltip on initialize time.

Here is following code i am using:

$('.help_tooltip').tooltipster({
    theme: 'tooltipster-shadow',
    functionInit: function(origin, content) {
        origin.tooltipster('content','testing content');// here i want to call my custom function 
    }
});

but when i run this code this giving me error:

Uncaught Error: You called Tooltipster's "content" method on an uninitialized element

I found in Documentation http://iamceege.github.io/tooltipster/#functionInitExample we can change text of tooltip on initialization.

Here is demo http://jsfiddle.net/w481vx1g/

Gitub Issue https://github.com/iamceege/tooltipster/issues/317

2个回答

    最佳答案
  1. I got this working by adding return

    $('.help_tooltip').tooltipster({
        theme: 'tooltipster-shadow',
        functionInit: function(origin, content) {
           return "new content';
        }
    });
    
  2. 参考答案2
  3. Wouldn't this do what you want too:

    $('.tooltip')
        .tooltipster({
            theme: 'tooltipster-shadow',
            content: test()
        });
    
    function test() {
        return $('<span><strong>See</strong> this is the new content.</span>');
    }