For example, if I have a button with an id “btn” and a form with the id “form” and I want to scrollto the form when I click on the button
HTML:
<p><a href="" id="btn">go to form</a></p> <form id="form"> </form>
jQuery:
$(document).ready(function(){ $("#btn").click(function(e){ e.preventDefault(); $('html, body').animate({ scrollTop: $("#form").offset().top }, 1000); }) })