Computer Magic Logo
Auto focus a input

Monday, June 12, 2017

Published by Aristotelis Pitaridis

Sometimes we want an input to be activated so that we will make the visitor's life easier. The following example of code demonstrates how to do it.

$(function () {
    $("#username").focus(); 
});

If we want to auto focus the first input of the web page we can use the following code.

$(function () {
    $("input:text:enabled:first").focus(); 
});