Categories
JavaScript Answers

How to scroll to an element using JavaScript?

Spread the love

To scroll to an element using JavaScript, we call the scrollIntoView method.

For instance, we write

document.getElementById("divFirst").scrollIntoView();

to select the element with getElementById.

Then we call scrollIntoView to scroll it into view.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *