scrollIntoView() method in javascript
scrollIntoView() method is used to move the screen to a target element.
Example Explanation
- In the above example, a list is created and for one list item we have given an id(id_b), it is the item where the windows has to be scrolled.
- When the button is clicked, javascript function is called.
- In the function, we are getting the particular list item using its id(document.getElementById("id_b");) and storing in elem variable.
- And using the scrollIntoView property the windows will be scrolled to the particular list item(elem.scrollIntoView();).
- The windows will be scrolled to the particular list item.