How to scroll to top when a button is clicked?
Try this code:
$("#button").on("click", function() {
$("body").scrollTop(0);
});
Method on
binds a click
event to the button and scrollTop
scrolls your body
to 0 position.
you can use window function for scrollTop
jquery
$("#button").click( function() {
$(window).scrollTop(0);
});
When you click button, this page scroll to top of the position.