I've looked very carefully for an answer to this question for hours and have not been able to come up with one.
I have a select box that changes background color based on the background color of the selected option. This feature works in Chrome but not in Firefox, where it just turns blue and stays blue regardless of which option you choose. The selected option's text appears in the select but not the background color.
I've already tried using css like ::selected {}
. The closest I've come is using a different StackOverflow answer to create a shadow box or to change the color when the focus changes, but no real luck so far.
Here is my code:
CSS:
#WHITE {background-color: white;}
#GRAY {background-color: rgb(194,194,194);}
#PINK {background-color: rgb(255,153,203);}
#YELLOW {background-color: rgb(254,255,153);}
#ORANGE {background-color: rgb(255,204,154);}
jQuery:
$(document).ready( function () {
var color = $("option:selected", "#colorSlct").css("background-color");
$("#colorSlct").css ("background-color", color);
});
$(document).on('change', '#colorSlct', function () {
var color1 = $("option:selected", this).css("background-color");
$("#colorSlct").css ("background-color", color1);
});
csp:
<select id = "colorSlct" type = "select" class = "select2" style = "margin-left: 0;">
<option id = "WHITE"> </option>
<option id = "GRAY" #($s(color="GRAY":"selected='selected'",1:""))#> Gray </option>
<option id = "PINK" #($s(color="PINK":"selected='selected'",1:""))#> Pink </option>
<option id = "YELLOW" #($s(color="YELLOW":"selected='selected'",1:""))#> Yellow </option>
<option id = "ORANGE" #($s(color="ORANGE":"selected='selected'",1:""))#> Orange </option>
</select>
Any tips would be appreciated. Thanks very much for your help.