Click here to Skip to main content
16,016,157 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Suppose I have a set of similiar control on a web page and I want to change the background of the control clicked. when another control of the group is clicked then the clicked control should have the changed colour and the previous control should regain its color. Haw can I achieve this?
Posted
Comments
Thanks7872 1-Sep-14 2:36am    
If you want to retain color of the clicked element till another one is clicked then you have to loop through each control on page and reset its background color. After that change the clicked element's as required.

e.g. btnTest is clicked. Then in its click event call the function which clears all the element's background color and you can skip the clicked one using $(this) [should be passed as an argument to the function] which would be the element you have clicked.

Click http://jsfiddle.net/shemeemsha/7pm6g2dc/[^]

Simple code.. You can use this method for changing background color of any control ..
 
Share this answer
 
create class in your style like bellow
.color
{
bgcolor="#E6E6FA";
}
and bellow condition to add that class
$("#yourID").addClass( "color" );
 
Share this answer
 
A Fiddle[^]

Above is a fiddle that changes the css for a button control on click.
Please check that.
Thanks
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900