Reputation: 1328
I am using a JQuery UI Tooltip along with AJAX to validate a form.
I am using one tooltip for each fields and I am changing the content of this tooltip depending on the error my AJAX return.
For my code to be complete I need to test if the tooltip is already initialize for this field (change content) if not (create the tooltip).
The problem is that I dont know any affective method of checking if the tooltip is initialize or not.
HTML:
<input type="text" id="text1"/>
<input type="text" id="text2"/>
I have tried the following but they all fail to test if the tooltip is already created or not.
JQUERY:
if($("#text1").tooltip() != null) //or $("#text1").tooltip() != 'undefined'
//does'nt work because .tooltip() always return an object.
if(typeof $("#text1").tooltip() != null)//or typeof $("#text1").tooltip() != 'undefined'
//does'nt work always return an object.
if($("#text1").tooltip().hasOwnProperty('option'))//or $("#text1").tooltip().hasOwnProperty('content')
//does'nt work it always return false.
If someone could help me find a way to check if the tooltip exist it'd be really appreciated
Thanks!
Upvotes: 7
Views: 12097
Reputation: 2041
Better to use the jquery-method is():
$('#timelinechecker').is(':ui-tooltip')
so you can use:
if($('#timelinechecker').is(':ui-tooltip')) {
// ... do what else...
}
Upvotes: 1
Reputation: 61773
Just an update if anyone is using a newer version, you can simply check for tooltipstered
class:
if (!$(this).hasClass("tooltipstered")) {
// Init
}
Upvotes: 1
Reputation: 1127
Just check data('ui-tooltip')
on your element. See example:
if($element.data('ui-tooltip')) {
$element.tooltip('destroy');
}
Upvotes: 24
Reputation: 1328
Resolve, I created a single tooltip that use the title attribute of my html elements. Instead of checking if the tooltip exist to create a new one or update the existing one I update the title attribute of the element.
Upvotes: 0