Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Autofocus Attribute in Html

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 449
    Comment on it

    Autofocus Attribute:

    It is a boolean attribute used with input fields, button that set focus on that element on which autofocus attribute has been used when a page is loaded. But we can focus only one element at a time using this attribute.

    Syntax:
     

    <input  type="text"  value=" " name=" " autofocus>
    
    <button type="button" autofocus>

    Example 1:

    <!DOCTYPE html>
    <html>
    <body>
    
    <form>
      <p>First name: <input type="text" name="first"></p>
      <p>Last name: <input type="text" name="last"></p>
      <p><button type="button" autofocus>Click Me!</button></p> 
    </form>
    
    </body>
    </html>

    It will focus on button when page is loaded.


    Example 2:

    <!DOCTYPE html>
    <html>
    <body>
    
    <form>
      <p>First name: <input type="text" name="fname" class="focus" autofocus></p>
      <p>Last name: <input type="text" name="lname"></p>
      <p><input type="submit"></p>
    </form>
    
    </body>
    </html>
    

    It wiil focus on input field with class="focus" when page will load.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: