Focus not work with pereventScroll

Focus not work with pereventScroll

It works only with .focus();

Any idea?


Hi there!

The problem is that you are using jQuery selectors instead of native JavaScript selectors. To make your code working properly, replace it with:

document.querySelector('span').addEventListener('click', function () {
        preventScroll: true

Thanks. By the way this means this cant work with jquery?

There is a difference between jQuery and JavaScript.

jQuery: the function “focus” can take “handler” (which is a function) as an argument. Here’s the link

Native JavaScript: the function “focus” can take “focusOption” which is an Object parameter. Here’s the link

1 Like

I think the support for preventScroll is also questionable Browser compatibility (Tested it in Firefox and it does not seem to work.)