This is not the answer you are looking for, but I will not attach tooltips directly to the elements. Instead, I would use a class for those that want the tooltip to appear when the mouse hovers and use the .on()
event handler as follows:
$('body').on('mouseover','.tooltip',function() { // show tooltip console.log($(this).data('tooltip')); return false; }).on('mouseout','.tooltip',function() { // hide tooltip return false; });
So, whatever you add to the body (not necessarily as a direct child), this trigger will handle the event.
I would simply create an additional function to assign tooltip data to each element along with the class.
$.fn.extend({ tooltip:function(text) { text = text || ''; return $(this).each(function() { $(this).data('tooltip',text).addClass('tooltip'); }); } }); $('#someID').tooltip("Click me!"); $('button').tooltip("I'm a button");
source share