Sometimes, we want to scroll a long page to DIV with JavaScript.
In this article, we’ll look at how to scroll a long page to DIV with JavaScript.
How to scroll a long page to DIV with JavaScript?
To scroll a long page to DIV with JavaScript, we call the scrollIntoView
method.
For instance, we write
document.getElementById("foo").scrollIntoView();
to select the element we want to scroll to with getElementById
.
Then we call scrollIntoView
to scroll to the element.
Conclusion
To scroll a long page to DIV with JavaScript, we call the scrollIntoView
method.