Reputation: 407
I have this sample:
CODE HTML:
<select name="card_type" id="card_type" class="select-full">
<option value="">Select</option>
<option value="visa">Visa</option>
<option value="mastercard">Mastercard</option>
<option value="discovery">Discovery</option>
<option value="maestro">Maestro</option>
</select>
CODE CSS:
select
{
color: #ccc;
}
option
{
color: #000;
}
option:first-child
{
color: red;
}
I have a wish to spot and select only the first item in the list. The first element to be red and the other to be gray for example.
Is there any possibility to do this? I tried the above code but does not work. Can you please tell me what is wrong?
Thanks in advance!
Upvotes: 3
Views: 106
Reputation: 838
I have made changes in snippet. Please check it.
is this the way you want?
$(document).ready(function(){
if($(this).val() == 0){
$('select').css("color","red");
}
else{
$('select').css("color","#000")
}
$('select').change(function(){
if($(this).val() == 0){
$('select').css("color","red");
}
else{
$('select').css("color","#000")
}
})
})
select
{
color: #ccc;
}
option
{
color: #000;
}
option:first-child
{
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="card_type" id="card_type" class="select-full">
<option value="0">Select</option>
<option value="visa">Visa</option>
<option value="mastercard">Mastercard</option>
<option value="discovery">Discovery</option>
<option value="maestro">Maestro</option>
</select>
Upvotes: 2
Reputation: 10187
Well assuming something.
I think you want your <option value="visa">Visa</option>
to color red but note that this is second option so use this css
select.select-full option:nth-child(2){
color:red;
}
fiddle link :https://jsfiddle.net/yudi/L439rrsd/
Upvotes: 1