Change or HTML TextBox background color on focus using jQuery

Introduction:  In this article I am going to share how to highlight HTML input or Asp.Net textbox on focus using focusin and focusout  methods of jquery   i.e. Change background color on focus. This trick also works for HTML textarea and multiline textbox.
Change background color of or HTML TextBox on focus using jQuery
In previous articles i explained how to Highlight or html textbox on mouse hover using jquery and Jquery to show hide password characters in textbox on checkbox check uncheck and How to Show jquery tooltip message on mouse over on controls  and How to Show tool tip message using css and html in controls and Show validation guidelines in web forms using javascript in

Implementation: Let’s create an example to demonstrate the concept.

HTML Source
<html xmlns="">
<head id="Head1" runat="server">
    <script src=""></script>
<script type="text/javascript">
        $(document).ready(function () {
            $('.txt').focusin(function () {
                $(this).css("background-color", "#fff4d8");
            $('.txt').focusout(function () {
                $(this).css("background-color", "#FFFFFF");
    <form id="form1" runat="server">
            <fieldset style="width:270px;">
                <legend>Highlight textbox on focus</legend>
                        <td>User Name:</td>
                            <asp:TextBox ID="txtUserName" CssClass="txt" runat="server"></asp:TextBox></td>
                            <asp:TextBox ID="txtPassword" TextMode="Password" CssClass="txt" runat="server"></asp:TextBox>                         

Highlight HTML input controls: If you want to implement the same for HTML textbox or then just replace the textbox  controls with html input controls as mentioned below and rest is same:
<input id=" txtUserName " type="text" class="txt" />
<input id=" txtPassword " type="password" class="txt"/>

Description: I have assigned a CSS class "txt" to the controls that I want to highlight on getting focus and through jquery I accessed the controls by the assigned class and changed the background color.

Now over to you:
A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates.
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..