-4

i have this code jQuery(document).ready(function() { // ajax pagination

  jQuery('#nav-above a').live('click', function() {
    var link = jQuery(this).attr('href');
    jQuery('#getlooping').html('<div id="skysode-loading">Loading...<img src="<?php echo get_template_directory_uri();?>/lib/images/loader-x.gif" alt="" class="load-url" /></div>');
     jQuery('#getlooping').load(link + ' #getlooping');
    return false;
  });
});

but error in get jquery file and not working

this error

Uncaught TypeError: jQuery(...).live is not a function at HTMLDocument.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
user4158643
  • 21
  • 1
  • 5
  • This has nothing to do with Java. I have deleted your question's Java tag and added a JavaScript tag. No sense drawing the wrong experts to your question. – Hovercraft Full Of Eels May 06 '20 at 22:14
  • [`.live()`](https://api.jquery.com/live/) was removed in 1.9. Use [`.on()`](https://api.jquery.com/on/) instead. – msg May 06 '20 at 22:18
  • @HovercraftFullOfEels I'm sorry, but my experience is minimal – user4158643 May 06 '20 at 22:20
  • @msg I have tried it and it works but only once and the second time it directs me to the link – user4158643 May 06 '20 at 22:22
  • @user4158643 your question asks about `.live` not working, not why your other code doesn't work when you use `.on`. Ask a new question if you have additional problems. (Make sure you use `.on` and not `.one`). Also you'll need to supply HTML as if you overwrite it with the .load the event won't exist anymore. – freedomn-m May 06 '20 at 22:33
  • Alternatively, use event delegation: `$(document).on("click", "#nav-above a", function() {...` – freedomn-m May 06 '20 at 22:34
  • Finally a search for "live is not a function" (the title in your question) provides a very comprehensive existing answer. – freedomn-m May 06 '20 at 22:35
  • @freedomn-m thaaaaaaaaaank yoooou this worked me $(document).on("click", "#nav-above a", function() { – user4158643 May 06 '20 at 22:39

1 Answers1

0

The live() function was deprecated from jQuery starting from version 1.7, and removed on version 1.9.

You have to replace it with on() function.

 jQuery(document).ready(function() { // ajax pagination
  jQuery('#nav-above a').on('click', function() {
    var link = jQuery(this).attr('href');
    jQuery('#getlooping').html('<div id="skysode-loading">Loading...<img src="<?php echo get_template_directory_uri();?>/lib/images/loader-x.gif" alt="" class="load-url" /></div>');
     jQuery('#getlooping').load(link + ' #getlooping');
    return false;
  });
});
Ahmed Hammad
  • 2,798
  • 4
  • 18
  • 35