Usage of autofocus HTML5 attribute

JavascriptWeb DevelopmentFront End Scripts

HTML5 introduced a new attribute called autofocus that would be used as follows:

<input type = "text" name = "search" autofocus/>

This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.

Example

You can try to run the following code to learn how to work with autofocus attribute:

<!DOCTYPE HTML>
<html>
   <body>
      <form action = "/cgi-bin/html5.cgi" method = "get">
         Enter email : <input type = "text" name = "newinput" autofocus/>
         <p>Try to submit using Submit button</p>
         <input type = "submit" value = "submit" />
      </form>
   </body>
</html>
raja
Published on 10-Apr-2018 16:30:12
Advertisements