Title

Wednesday, 4 February 2015

Force cursor to input box immediately after webpage is loaded


I would like to force the cursor to go to an input field immediately after the webpage is loaded. I am using AngularJS and the HTML code for the input field is as follows;

 <form novalidate="" class="simple-form">Identity number   <input type="text" ng-model="input_number" />   <br />   <button ng-click="submit()">SUBMIT</button></form>

How can this be done the AngularJS way? If not, using normal javascript or jquery are also welcomed.

Answer

You can use .focus() with jQuery:

$('form input[type=text]:eq(0)').focus();

No comments:

Post a Comment