• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 912
  • Last Modified:

Change css background style onclick asp.net textbox

Hi,

I would like to have a jquery script that changes the background in my asp.net textboxes on my form when I click them and goes back to the previous style when I click on another element of the page.

Can someone show me how to achieve this?

Thanks for help!

Peter
0
peternordberg
Asked:
peternordberg
1 Solution
 
Roopesh ReddyCommented:
Hi,

Check the below code!

  <asp:TextBox runat="server" />  

    <script type="text/javascript">
        $(document).ready(function () {
            $('input[type=text]').focus(function () {
                $(this).css("background", "#0f0");
            });
            $('input[type=text]').blur(function () {
                $(this).css("background", "#fff");
            });
        });
    </script>

Open in new window


Hope it helps u...
0
 
Chris StanyonCommented:
Unless you have a specific need to do this with jQuery, you can do it using just CSS.

input[type=text] { background-color:green; }
input[type=text]:focus { background-color:red; }

Open in new window

0
 
peternordbergAuthor Commented:
Perfect!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now