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
Peter NordbergIT ManagerAsked:
Who is Participating?
 
Roopesh ReddyConnect With a Mentor IT AnalystCommented:
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
 
Peter NordbergIT ManagerAuthor Commented:
Perfect!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.