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?
The tooltip position is specified with two different configuration properties: position and offset . The position property specifies the position in relation to the trigger element. For example, a value of 'bottom center' will place the tooltip on the bottom edge of the trigger, centered horizontally.
The tooltip content can be changed dynamically using the AJAX request. The AJAX request should be made within the beforeRender event of the tooltip. On every success, the corresponding retrieved data will be set to the content property of the tooltip.
Tooltips can be attached to any element. To display tooltips, just add title attribute to input elements and title attribute value will be used as tooltip. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element.
The jQuery UI tooltip() method adds tooltip to any element on which you want to display tooltip. It gives a fade animation by default to show and hide the tooltip, compared to just toggling the visibility. Syntax: You can use the tooltip() method in two forms.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With