JQuery set .focus()

JQuery set .focus()

.focus() sets focus on given element. You may want to set focus on texbox or checkbox or radio buttons when document is loaded in browser.

.focus() example

<script type="text/javascript" language="javascript"> 

    $("document").ready(function(){
    
         $("#txtFirstName").focus();
         
     });
     
 </script>

In above JQuery focus example, we are setting focus on txtFirstName input textbox.

Complete JQuery Focus example with HTML.

<html>
<head>
    <title>JQuery set focus example</title>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript"> 
   
       $("document").ready(function(){
       
            $("#txtFirstName").focus();
            
        });
        
    </script>

</head>
<body>
    <div id="div1">
        First Name: <input id="txtFirstName" type="text" /></br>
        Last Name:<input id="txtLastName" type="text" /></br>
        Email:     <input id="txtEmail" type="text" />
    </div>

</body>
</html>

This is how you can achieve auto focus element using JQuery focus handler.

Tags:

Jquery

Learning JqueryBasics of jqueryJQuery auto .focus()JQuery access label control and set valueJQuery Set Value of Textbox or Label Control In Asp.netJQuery Hidden Field Set ValueJquery Set Value Of Textbox.JQuery SlideJquery Trim StringYahoo email settingsJQuery Animate Div Height and Width

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.