7

Possible Duplicate:
How to set the focus to the first input element in an HTML form independent from the id?

I'm using BootStrap with ASP.NET MVC4. There is one login form but I'm unable to set focus on first input field.

How to set focus on first field of input? Is there any BootStrap class that uses to set focus?

Community
  • 1
  • 1
Dharmik Bhandari
  • 1,702
  • 5
  • 29
  • 60

1 Answers1

25

There isn't a Bootstrap-specific class or function that does this*, but HTML5 provides the autofocus attribute for input fields.

This attribute currently enjoys wide browser support.

*-Since you are using Bootsrap, and Bootstrap is powered by jQuery, you could "shim" older browsers that otherwise don't support autofocus:

$('[autofocus]:first').focus();
Jeromy French
  • 11,812
  • 19
  • 76
  • 129