简体   繁体   中英

tooltip on dynamic created content in jquery

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" );
    }
}); 

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM