How to Scroll to an Element using JavaScript

Scroll to Div functionality is used to scroll the page to a specific element automatically. The page will navigate to a specific section of the page without scrolling manually. The scroll to HTML element feature can be integrated using JavaScript.

The scrollIntoView() method of the JavaScript Element interface scrolls the page to the element container. The scrollIntoView() method helps scroll to an element using JavaScript.

The following code snippet scrolls page to a specific element with JavaScript.

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

The above code will scroll the page to the element that has id elementID.

<div id="elementID">
    ...
</div>

Leave a reply

keyboard_double_arrow_up