Avatar ·

How to smoothly scroll the page to the desired element using jQuery?

Hello everyone! I just started learning jQuery and ran into a problem. I have a long form on my page, and after submitting the data, I want to automatically scroll the page to the block with a success or error message. But the standard `#id` anchor works too abruptly — the page just jumps, and the user loses context.\n\nI tried using `window.scrollTo()`, but it only accepts coordinates, and I need the scroll to be smooth. Here is my current code, which doesn't work as desired:\n\n```javascript\n$('#submit-btn').on('click', function() {\n // ... sending data via AJAX ...\n // On success:\n window.scrollTo(0, $('#success-message').offset().top);\n});\n```\n\nThe scrolling happens instantly, without animation. I heard that jQuery has a method `.ani