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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With