Html input, always in focus

How can I keep html input always in focus? Using the autofocus attribute when creating an element helps to focus on pageload, but does not focus on the object. Is there an easy way to keep focus there?

+5
source share
1 answer

Try the following:

 <!-- On blur event (unfocus) refocus the input --> <input onblur="this.focus()" autofocus /> <input value="Can't focus on this" /> 

Basically, you add a blur event (which happens whenever the input loses focus), and in the blur event, you focus on the input. In addition, you add the autofocus attribute to start focusing as well.

PS If you plan to use this for a website for real users, from a user interface point of view, this is probably not a good idea.

+17
source

Source: https://habr.com/ru/post/1206371/


All Articles