JQuery UI Tooltip AJAX Click/Mouseover

JQuery UI Tooltip AJAX Click/Mouseover

Dear All,

I've put together subsequent code to show up dynamic content coming from an AJAX call.

The call as well as showing up the tooltip works but the trigger mechanism is a bit weird.

My aim it to

a) show the tooltip when clicking the DIV container and 
b) to close the tooltip once I leave the DIV container

But what actually happens is:

c) When I click nothing happens and 
d) when I then move over the DIV container the tooltip appears (every time I move over the container)

Does anybody know how to correct my code in order to achieve a and b?

Best Regards,

Stefan

  1. <script type="text/javascript">
  2.     $('document').ready(function() {
  3.         
  4.         $('.ajax').click(function() {
  5.             
  6.             // Fetch the game id from id attribute
  7.             var thisSelector = $(this);
  8.             var gameId = $(this).attr("id");
  9.             $.ajax({
  10.                 type: "GET",
  11.                 url: "http://server:8080/games/"
  12.                         + gameId,
  13.                 dataType: 'jsonp',
  14.                 jsonpCallback: "fn",
  15.                 crossDomain: true,
  16.                 success: function(data) {
  17.                     
  18.                     $( thisSelector ).tooltip({ 
  19.                         open: function( event, ui ) {
  20.                             console.log("c");
  21.                         },
  22.                         content: function() {
  23.                             return '<span id="msg" STYLE="font-size: 10pt"><center><img src="images/pic.png" border="4" alt="some_text"></center><br>' + parseJSON(data) + '</span>';
  24.                         }
  25.                     });
  26.                     
  27.                 },
  28.                 error: function(jqXHR, textStatus, errorThrown) {
  29.                     console.log('error');
  30.                     console.log(errorThrown);
  31.                     console.log(jqXHR);
  32.                 }
  33.             });                     
  34.         });