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

javascript - tooltip on dynamic created content in jquery - Stack Overflow

programmeradmin3浏览0评论

How to trigger the tooltip from a content has just created dynamically from jquery?

I use append function to append a "p" element into a content and with title attribute as well.

Every time I need to hover twice on the a newly created element then the tooltip box will appear. Otherwise hovering on the element first time will show nothing always.

This is my tooltip function. Or maybe I can get the class name and do the matching somehow. Please do guide me.

$(".tooltip_class").tooltip({
    show: null,
    position: {
        my: "left top",
        at: "left bottom"
    },
    open: function( event, ui ) {
        ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" );
    }
}); 

How to trigger the tooltip from a content has just created dynamically from jquery?

I use append function to append a "p" element into a content and with title attribute as well.

Every time I need to hover twice on the a newly created element then the tooltip box will appear. Otherwise hovering on the element first time will show nothing always.

This is my tooltip function. Or maybe I can get the class name and do the matching somehow. Please do guide me.

$(".tooltip_class").tooltip({
    show: null,
    position: {
        my: "left top",
        at: "left bottom"
    },
    open: function( event, ui ) {
        ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" );
    }
}); 
Share Improve this question edited Jan 9, 2017 at 11:34 Raviteja 3,48923 gold badges45 silver badges74 bronze badges asked Mar 16, 2014 at 18:07 MichaelMichael 891 gold badge1 silver badge8 bronze badges 5
  • can you post a fiddle showing the problem? or the code you're using for the tooltip? – T J Commented Mar 16, 2014 at 18:33
  • currently my code is $(document).tooltip({ show: null, position: { my: "left top", at: "left bottom" }, open: function( event, ui ) { ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" ); } }); – Michael Commented Mar 16, 2014 at 18:35
  • I want to get the class name so i can match it to whether to show the tooltip or not. because i have other element which contain title as well but not all title must show inside a jquery tooltip – Michael Commented Mar 16, 2014 at 18:37
  • please update the code in your question, not everyone reads the ments.. – T J Commented Mar 16, 2014 at 18:39
  • @Michael You need to put the HTML code here, if you want others to help you. – Foreever Commented Mar 19, 2014 at 4:58
Add a ment  | 

1 Answer 1

Reset to default 5

You do not need to put the content as title attribute value. Instead the content can be added in jQuery as follows:

Javascript

$( document ).tooltip();
$('#selector').tooltip( "option", "content", "TOOLTIP CONTENT" );

HTML

<span class="help">
 <a id="selector" title="">  
    What's this?
</a>
</span>

See Demo

发布评论

评论列表(0)

  1. 暂无评论