I perform an action with jQuery every time a textfield is focused on my website. Everything works fine as long as I manually focus on the textfield by clicking on it.
However: I’m using HTML5’s autofocus feature, and jQuery doesn’t detect that a textfield automatically has been focused. How can I make sure that my script performs an action whether a textfield has been manually or automatically focused?
Right now, I’m using…
$("input:text, input:password").focus(function() { });
… to detect when a textfield is highlighted.
If you only need to worry about autofocus on the initial page load then maybe something like this?
Trigger the focus event on autofocus’d elements on pageload: