How do I Update the Content in Jquery UI Tooltip in Realtime?

Nicholas Cardot picture Nicholas Cardot · Apr 4, 2013 · Viewed 31.7k times · Source

I have an element that when hovered over, it displays the price of the item (in a game). I'm using the jQuery UI tooltip to power the display of the information about each item. When the item is clicked, jQuery captures the click, uses a $.get() request to process the purchase and can return specific information related to the item via JSON and jQuery's parseJSON feature.

However, the prices of each item change with each purchase. It's sort of a form of inflation. I can't figure out how to access the content of the jQuery UI tooltip to change it's content so that while it is still displayed or even when it's not displayed, to change the value of it's content to reflect the new prices.

What do I need to do to change that content in real time?

Answer

Foreever picture Foreever · Jan 19, 2014

You can change the content of jQuery Tooltip after initialization as follows:

$( ".selector" ).tooltip( "option", "content", "Awesome title!" );

Here is a demo.

See the API for more details.