How to get the text within a span in a tooltip via jQuery?

≡放荡痞女 提交于 2019-12-13 07:00:01

问题


I am trying to get the text within a span to be the 'content' of a tooltip using the Tooltipster jQuery plugin.

A description of the available parameters for the 'content' option can be seen here:

http://calebjacob.com/tooltipster/#options

JQuery

<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster({
content: $(this).parent().text() // trying to get the span text here
});
});
</script>

HTML

<p>Here is some text, and here is <span class="tooltip" data-rlink="<a href=&quot;http://www.google.com&quot;>a link</a>">SOME MORE</span> text.</p>
<p>And the content should be <span class="tooltip">UNIQUE</span> to the instance.</p>

jsFiddle

http://jsfiddle.net/rwone/y9uGh/1/

Solution

Based on the answer below, this was the implementation I went with. The snippet below shows integration of the js solution with the plugins parameters:

<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster({
functionBefore: function(origin, continueTooltip){
origin.tooltipster('update', $(origin).text());
continueTooltip();
},
animation: 'grow',
arrow: false,
});
});
</script>

回答1:


Try

$(document).ready(function() {
    $('.tooltip').tooltipster({
        functionBefore: function(origin, continueTooltip){
            origin.tooltipster('update', $(origin).text());
            continueTooltip();
        }
    });
});

Demo: Fiddle



来源:https://stackoverflow.com/questions/18179242/how-to-get-the-text-within-a-span-in-a-tooltip-via-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!