使用工具提示器动态更改工具提示标题中的一个元素

afa*_*olo 1 jquery tooltip tooltipster

我在tooltipster title属性中有一组选项,如下所示:

<i class="icon-cog settings" title="
                   <div class='div1' onclick='follow(1,2)'>Content 1</div>
                   <div class='div2' ...>Content 2</div>
                   <div class='div3' ...>Content 3</div>
                                                   ">
</i>
Run Code Online (Sandbox Code Playgroud)

单击div1时,内容将根据以下函数通过ajax结果进行动态更新:

function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
    $('.div'+f2).html('content 1 is updated to' + result.newcontent);
    }, 'json');
}
Run Code Online (Sandbox Code Playgroud)

问题是当关闭工具提示并且页面尚未刷新时,内容将返回初始值,而不是显示更新的值.

我试图用一个配置选项描述这里:

function follow(f1,f2) {
    $.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
        // $('.div'+f2).html('content 1 is updated to' + result.newcontent);
        $('.settings').tooltipster('update', 'content 1 is updated to' + result.newcontent);
        }, 'json');
} 
Run Code Online (Sandbox Code Playgroud)

但是,这会更改div1的内容,但会删除其他div的内容.如何仅更新div1的内容并保持其他内容不变?

== ==编辑

我更喜欢不通过所有div组的解决方案,如下所示:

function follow(f1,f2) {
    $.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
        $('.settings').tooltipster('update', '
                                              <div class='div1' onclick='follow(1,2)'>'+result.newcontent+'</div>
                                              <div class='div2' ...>Content 2</div>
                                              <div class='div3' ...>Content 3</div>
                                             ');
        }, 'json');
}
Run Code Online (Sandbox Code Playgroud)

Roy*_*uli 7

我发现这个命令可以改变标题:

$('#selectorElement').tooltipster('content', 'new title');
Run Code Online (Sandbox Code Playgroud)