Categories
JavaScript Answers

How to scroll long page to div with JavaScript?

Spread the love

Sometimes, we want to scroll long page to div with JavaScript.

In this article, we’ll look at how to scroll long page to div with JavaScript.

How to scroll long page to div with JavaScript?

To scroll long page to div with JavaScript, we can select the element to scroll to and call scrollToView on it.

For instance, we write

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

to select the element with ID youridhere with getElementById.

Then we call scrollIntoView to scroll to the element.

Conclusion

To scroll long page to div with JavaScript, we can select the element to scroll to and call scrollToView on it.

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 *