Search code examples
jquerytooltipdynamic-htmltooltipster

Using tooltipster Dynamically Jquery


I use tooltipster plugin for my tooltip

$(function(){
     $('.tooltip').tooltip();
});

Now the .tooltip that were added later dynamically does not respond to tooltip()

Now many will say to call $('.tooltip').tooltip(); each time i add those elments. But since i have hundreds of thousands of elements that contain .tooltip and are created from hundrends of functions I cannot call the $('.tooltip').tooltip(); hundred times . Is there any alternative ?


Solution

  • In such cases, delegate listeners are a good option. You listen for mouseenter events (for example) on a common ancestor and create and show the tooltip on the hovered child accordingly. Tooltipster has API methods that allow this.