Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> <style> #divId { height: 1200px; background: green; } </style> </head> <body> <div id='divId'> <button id='elem'>Click to scroll</button> </div> <script> const btn = document.getElementById('elem'); btn.addEventListener('click', () => window.scrollTo({ top: 500, behavior: 'smooth', })); </script> </body> </html>