Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html input, always in focus

Tags:

html

css

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

like image 554
Mia Avatar asked Nov 06 '14 22:11

Mia


1 Answers

Try this:

<!-- 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 occurs whenever the input loses focus), and in the blur event, you focus on the input. In addition, you add the autofocus attribute to start off focused as well.

P.S. If you are planning to use this for a website for actual people to use, from a user interface perspective, this is probably not a great idea.

like image 115
soktinpk Avatar answered Sep 28 '22 11:09

soktinpk