jQuery.ScrollTo scrolling rewind is called by this script:

jQuery(document).ready(function(){ jQuery('.bp-pager').click(function() { jQuery.scrollTo('#wrapper'); }); }); 

But after the ajax load occurs, it stops working. I read that I need to add an event handler, but I don’t understand how to write it correctly.

I tried it like this

 jQuery(document).ready(function(){ jQuery('.bp-pager').live("click", function(){ jQuery.scrollTo('#wrapper'); }); }); 

generally stopped working.

Answer:

 $('.db_wrapper').on('click', '.bp-pager', function(){ jQuery.scrollTo('#wrapper'); }); 

.db_wrapper is a block that wraps content loaded by ajax.

Dmitry helped with the decision only with the body did not work.

Reported as a duplicate by Visman members, aleksandr barakin , lexxl , user194374, Grundy Aug 5 '16 at 12:59 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • 2
    It is not clear how ajax is related to the problem. Most likely, ajax request loads html content that replaces the original html, on which you install the click event handler. Try this with jQuery('body').on("click", ".bp-pager", function(){ jQuery.scrollTo('#wrapper'); }); - Dmitry
  • No, that doesn't work. You correctly understood Ajax loads the content inside which bp-pager are located - l2banners
  • This is how $ ('. Db_wrapper'). On ('click', '.bp-pager', function () {jQuery.scrollTo ('# wrapper');}); - l2banners
  • .db_wrapper is a block that wraps content loaded by ajax - l2banners

2 answers 2

1. Upload jquery script via async :

 <script async type="text/javascript" src="path/to/your/js/file"></script> 

2. If the function does not work through jQuery(document).ready() drop the function on loading in the body :

 <body onload="yourFunction()"> //Content </body> 

    Answer:

     $('.db_wrapper').on('click', '.bp-pager', function(){ jQuery.scrollTo('#wrapper'); }); 

    .db_wrapper is a block that wraps content loaded by ajax.