focus() to input without scrolling

There is a new WHATWG standard which allows you you to pass an object to focus() which specifies that you want to prevent the browser from scrolling the element into view:

const element = document.getElementById('search-terms')

element.focus({
  preventScroll: true
});

It has been supported since Chrome 64 and Edge Insider Preview build 17046, and should be landing in Firefox 68 – a support matrix is available on web-platform-tests here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)