Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Tooltip doesn't work after ajax load

I have this code on my site:

$(document).ready(function() {

  $('.tooltip-game').jBox('Tooltip', {
    closeOnMouseleave: true,
    ajax: {
      url: 'tooltips/tooltip-game-html.jsp',
      reload: true,
      getData: 'data-ajax',
      setContent: true,
      spinner: true
    }
  });

  $( '#tabs-1' ).tabs({
    beforeLoad: function( event, ui ) {
      ui.panel.html('<div style="text-align: center; vertical-align: middle;"><img src="images/loading.gif" />');
      ui.jqXHR.fail(function() {
        ui.panel.html("Couldn't load this tab. We'll try to fix this as soon as possible." );
      });
    }
  });
});

I use jQuery Tabs and jQuery tooltips, but after loading external file with ajax, tooltips don't work. I know i have to use .on() function, but I don't know how :(

Thank you very much for your tips.

like image 464
Harrison Avatar asked Dec 11 '25 12:12

Harrison


1 Answers

You need to initialize tooltips after asynchronous call ends.

 function tooltips() {              
  $('.tooltip-game').jBox('Tooltip', {
    closeOnMouseleave: true,
    ajax: {
      url: 'tooltips/tooltip-game-html.jsp',
      reload: true,
      getData: 'data-ajax',
      setContent: true,
      spinner: true,
     //Take a look to this line
      success: function() {
            tooltips();
      }
    }
  });
 }    


  $( '#tabs-1' ).tabs({
    beforeLoad: function( event, ui ) {
      ui.panel.html('<div style="text-align: center; vertical-align: middle;"><img src="images/loading.gif" />');
      ui.jqXHR.fail(function() {
        ui.panel.html("Couldn't load this tab. We'll try to fix this as soon as possible." );
      });
    }
  });
});
like image 50
Marcos Pérez Gude Avatar answered Dec 14 '25 04:12

Marcos Pérez Gude