How to go to a specific element on page with JavaScript?

Sometimes, we want to go to a specific element on page with JavaScript.

In this article, we’ll look at how to go to a specific element on page with JavaScript.

How to go to a specific element on page with JavaScript?

To go to a specific element on page with JavaScript, we can use the element’s scrollIntoView method.

For instance, we write

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

to get the element we want to scroll to with

document.getElementById("elementID")

Then we call scrollIntoView to scroll to the element.

Conclusion

To go to a specific element on page with JavaScript, we can use the element’s scrollIntoView method.