Reputation: 133
<select id="select">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<span id="red">red </span> <span id="default">default</span>
$("#red").click(function(){
$("#select").css('background-color', 'red');
});
$("#default").click(function(){
$("#select").css('background-color', 'white');
});
if i click RED then select is red. how can i set default style for select, against white?
Upvotes: 1
Views: 375
Reputation: 38264
Just remove the property to reset the background color to its default:
$("#default").click(function(){
$("#select").css('background-color', '');
});
For reference, see the jQuery .css()
docs. Quote:
Setting the value of a style property to an empty string — e.g.
$('#mydiv').css('color', '')
— removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property.
Upvotes: 5