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.