change background color of textbox on click using jquery

Posted by Klbaiju under jQuery on 1/4/2013 | Points: 10 | Views : 7731 | Status : [Member] | Replies : 3
Hi all,
In my application , when i click on any text box , i want to change the backgroundcolor.when i click another text box i want to change
the background color of later to another.
i tried using addclass and removeclass using jquery

$(':text').click(function(){
$(this).addClass("highlight");
},
function() {
$(this).removeClass("highlight");
});


});


<style type="text/css">
.highlight
{
background-color:#9999FF;
}

</style>

it is working on first time.
when i press second textbox ,first text box's background color is not changing

how to solve this

Regards
Baiju




Responses

Posted by: Raj.Trivedi on: 2/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Klbaiju

http://www.aspdotnet-suresh.com/2012/10/jquery-change-textbox-background-color.html

This will solve your issue.

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Devi0074u on: 3/12/2013 [Member] Starter | Points: 25

Up
0
Down
You have to use focus and blur event instead of click event.

Check the running example: http://jsfiddle.net/VHXEc/

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimi1289 on: 6/13/2013 [Member] Starter | Points: 25

Up
0
Down
Are you doing any postback once focus is lost from the 1st textbox? If that is the case then you need to bind the controls using JQuery "$(document).ready(function() "

Try this...

$(document).ready(function() {

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

BindControls();
});
function InitializeRequest(sender, args) {}
function EndRequest(sender, args) {BindControls();}

function BindControls() {
bind all your controls here...
}


Meanwhile you can check this article also on changing colors of any element using JQuery.
http://www.encodedna.com/2013/06/jquery-color-animation.htm

Demo
http://www.encodedna.com/2013/06/jquery-color-animation.htm#animDiv

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response