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?
How to set focus on input field or textarea inside a Bootstrap modal on activation. Answer: Use the jQuery .focus() method. You can use the jQuery .focus() method to set focus on the first input box or textarea inside the Bootstrap modal when its load upon activation, like this: Example. $(this).find('#inputName').focus();
Is there any BootStrap class that uses to set focus? 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.
Answer: Use the CSS box-shadow Property By default, all the textual <input> elements, <textarea>, and <select> elements with the class.form-control highlighted in blue glow upon receiving the focus in Bootstrap. However, you can modify this default focus glow or shadow styles by simply setting the CSS border-color and box-shadow property.
The onload event executes a function that finds the input field with the firstField ID via document.getElementById and then uses the JavaScript focus () method to set the state of the input field to focus. Does the focus outline disappear from your input field all of a sudden?
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();
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