smo smo - 5 months ago 31
jQuery Question

jQuery Tools Tooltip - Change Title

Got a problem with the jquery plugin Tools tooltip (http://flowplayer.org/tools/tooltip/index.html)
I need to change the title of the element..

reloadTooltip();
$("#example").attr('title', obj.text);
reloadTooltip();

function reloadTooltip(){
$("[title]").tooltip({ position: "bottom right", opacity: 1 });
}


Html Part:

<span title="text" id="example"></span>


With my solution i got finally 2 titles, one above the other. The unstyled (ignored js), is the new one. The Tools tooltip title has not changed yet.

thank you

Answer

I'm about to do the same thing. I looked through the Tooltip plugin code, and discovered as quick and easy way to update the tooltip. The plugin removes the title attribute and puts that content into an element property called tooltipText. In jQuery 1.6+, it can be manipulated like so:

// get the current tooltip content
$('#someElement').prop('tooltipText')

// set the tooltip content
$('#someElement').prop('tooltipText', 'w00t');

The plugin sets the tooltipText property (note the capitalization) at line 55 in version 1.3. Changes done this way are instantaneous as far as I can tell.

If doing direct element manipulation, the tooltip content is at:

var e = document.getElementById('#someElement');
alert(e.tooltipText);
e.tooltipText = 'w00t';