Javascript Question

Scroll to top button redirecting to Homepage

So, this script is on my footer.php, and when button is pressed it redirects to homepage instead of top.

$(document).ready(function() {


$("#arriba").click(function() {


return $("html, body").animate({


scrollTop: 0


}, 1250), !1


})


});



UPDATE:

Thanks so much all, I found the solution, the code above was inserted into a php instance, I created a new javascript instance out of the php and it's working fine all the codes presented here!

Answer

You need to use preventDEfault to stop behavior of your button or anchor tag:

$(document).ready(function() {
        $("#arriba").click(function(e) {
            e.preventDefault()
            $("html, body").animate({
                scrollTop: 0
            }, 1250);
        })
    }); 

EDIT:

try also this:

$(document).ready(function() {
    $("#arriba").click(function(e) {
         e.preventDefault()
         window.scrollTo(0, 0);
    })
});