Reputation: 10964
I found this helpful jsfiddle on adding tooltips with jQuery.
How could I get the same results but with dynamically created elements?
Without any plugins, if thtas possible.
Depending on which options a user ticks, my div will display one of three coloured circles to show the importance of a task. Can I add a tooltip to the circles in a manner such as this?
jQuery(function() {
jQuery( '.veryImportant' ).tooltip();
});
Upvotes: 9
Views: 16362
Reputation: 1946
The only working solution for me was using createdRow
in datatables, see Tooltip doesn't work on datatables child rows
Upvotes: 0
Reputation: 104775
You just add the tooltip how you normally would, only make sure that you are calling .tooltip()
AFTER the element has been added to the page. Based on your code, it seems you're trying to add it immediately, and if that element doesn't exist, it will never get it.
Simple sample:
<div id='test'>im a div</div>
$("#test").append("<span id='spantest'>hey</span>");
$("#spantest").tooltip(); //works fine, since the element exists at time of call
Upvotes: 8