Autify JavaScript Snippets
Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto mode Back to homepage
Edit page

Scroll until an element is displayd

IE11 not supported
This snippet does not support IE11.

Scroll down the page until the specific element is displayed.

Change the following value to specify the element:

  • selector: A string of the element selector
 * Locate the element
var selector = "<TODO: REPLACE SELECTOR>";
var element = document.querySelector(selector);

 * Stop process if it does not exist
if (!element) {
  throw new Error(
    "Error: cannot find the element with selector(" + selector + ")."

 * Scroll until the element is displayed.
 * If the block value is set to "center", the element will scroll to the center of the page.
element.scrollIntoView({block: "end", inline: "nearest", behavior: "smooth"});