0

From this answer, I have the following after my <body>:

<a name="Pagetop"></a>

In my footer, I have:

<script>
    jQuery(".pgtop").click(function() {
        jQuery('html, body').animate({
            scrollTop: jQuery("#Pagetop").offset().top
        }, 2000);
    });
</script>
<p class="pgtop"><img src="<?php echo get_stylesheet_directory_uri() ?>/images/up-arrow.png" alt ="Go to top of page" title ="Go to top of page" width="50" height="29" border = "0" ></p>

but the scroll to top does not work on this staging site.

Help appreciated.

Steve
  • 2,509
  • 11
  • 48
  • 88

1 Answers1

0

Change your page-top target element to use id instead of name property

<a id="Pagetop"></a>

Also, wait for your page to load before binding the element.

 jQuery(document).ready(function () {
    jQuery(".pgtop").click(function () {
        jQuery('html, body').animate({
            scrollTop: jQuery("#Pagetop").offset().top
        }, 2000);
    });
});
angus
  • 680
  • 8
  • 23