简体   繁体   中英

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.

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." );
      });
    }
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM