JS/CSS Code working for Chrome but not Firefox












2















I have some html and JavaScript for a select drop-down box. When the user selects the color I want the background of the selected option to successfully update with the color of the background.



In the code I am experiencing what is occurring with Firefox, when you hover over a select option it changes the hover color to blue, and when you select it it takes that background color.



When I run the exact same code in Chrome, it successfully uses the background color of the selected option.



What can I do to make this cross platform compatible and work?






    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>





enter image description here










share|improve this question

























  • Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

    – Scott Marcus
    Nov 27 '18 at 23:26











  • it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

    – ADyson
    Nov 27 '18 at 23:28













  • related: support.mozilla.org/de/questions/1141257

    – Jeff
    Nov 27 '18 at 23:31











  • $("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

    – TechnoCorner
    Nov 27 '18 at 23:31











  • The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

    – 97WaterPolo
    Nov 27 '18 at 23:44
















2















I have some html and JavaScript for a select drop-down box. When the user selects the color I want the background of the selected option to successfully update with the color of the background.



In the code I am experiencing what is occurring with Firefox, when you hover over a select option it changes the hover color to blue, and when you select it it takes that background color.



When I run the exact same code in Chrome, it successfully uses the background color of the selected option.



What can I do to make this cross platform compatible and work?






    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>





enter image description here










share|improve this question

























  • Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

    – Scott Marcus
    Nov 27 '18 at 23:26











  • it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

    – ADyson
    Nov 27 '18 at 23:28













  • related: support.mozilla.org/de/questions/1141257

    – Jeff
    Nov 27 '18 at 23:31











  • $("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

    – TechnoCorner
    Nov 27 '18 at 23:31











  • The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

    – 97WaterPolo
    Nov 27 '18 at 23:44














2












2








2








I have some html and JavaScript for a select drop-down box. When the user selects the color I want the background of the selected option to successfully update with the color of the background.



In the code I am experiencing what is occurring with Firefox, when you hover over a select option it changes the hover color to blue, and when you select it it takes that background color.



When I run the exact same code in Chrome, it successfully uses the background color of the selected option.



What can I do to make this cross platform compatible and work?






    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>





enter image description here










share|improve this question
















I have some html and JavaScript for a select drop-down box. When the user selects the color I want the background of the selected option to successfully update with the color of the background.



In the code I am experiencing what is occurring with Firefox, when you hover over a select option it changes the hover color to blue, and when you select it it takes that background color.



When I run the exact same code in Chrome, it successfully uses the background color of the selected option.



What can I do to make this cross platform compatible and work?






    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>





enter image description here






    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>





    $("#color_me1").change(function(){
var color = $("option:selected", this).css("background-color");
$("#color_me1").css("background-color", color);
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Color One:</label>
<select id="color_me1" name="color1">
<option disabled selected value> -- select color -- </option>
<option value="800000" style="background-color:#800000">Maroon</option>
<option value="FF0000" style="background-color:#FF0000">Red</option>
<option value="FFA500" style="background-color:#FFA500">Orange</option>
<option value="FFFF00" style="background-color:#FFFF00">Yellow</option>
<option value="808000" style="background-color:#808000">Olive</option>
<option value="008000" style="background-color:#008000">Green</option>
<option value="800080" style="background-color:#800080">Purple</option>
<option value="FF00FF" style="background-color:#FF00FF">Fuchsia</option>
<option value="00FF00" style="background-color:#00FF00">Lime</option>
<option value="008080" style="background-color:#008080">Teal</option>
<option value="00FFFF" style="background-color:#00FFFF">Aqua</option>
<option value="0000FF" style="background-color:#0000FF">Blue</option>
<option value="000080" style="background-color:#000080">Navy</option>
<option value="808080" style="background-color:#808080">Gray</option>
<option value="FFFFFF" style="background-color:#FFFFFF">White</option>
</select>
<br>






javascript html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 23:24









Scott Marcus

39.5k52038




39.5k52038










asked Nov 27 '18 at 23:19









97WaterPolo97WaterPolo

5110




5110













  • Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

    – Scott Marcus
    Nov 27 '18 at 23:26











  • it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

    – ADyson
    Nov 27 '18 at 23:28













  • related: support.mozilla.org/de/questions/1141257

    – Jeff
    Nov 27 '18 at 23:31











  • $("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

    – TechnoCorner
    Nov 27 '18 at 23:31











  • The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

    – 97WaterPolo
    Nov 27 '18 at 23:44



















  • Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

    – Scott Marcus
    Nov 27 '18 at 23:26











  • it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

    – ADyson
    Nov 27 '18 at 23:28













  • related: support.mozilla.org/de/questions/1141257

    – Jeff
    Nov 27 '18 at 23:31











  • $("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

    – TechnoCorner
    Nov 27 '18 at 23:31











  • The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

    – 97WaterPolo
    Nov 27 '18 at 23:44

















Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

– Scott Marcus
Nov 27 '18 at 23:26





Styling of form elements is not consistent across clients. All you could do is work with proprietary CSS for a particular client.

– Scott Marcus
Nov 27 '18 at 23:26













it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

– ADyson
Nov 27 '18 at 23:28







it could be a bug in Firefox, or maybe they just don't support that feature. It's not controlled by any standard which would apply to all browsers. Quick internet research shows it may be a bug, although Firefox claim to have fixed it, others beg to differ. See stackoverflow.com/questions/44147362/…, for instance

– ADyson
Nov 27 '18 at 23:28















related: support.mozilla.org/de/questions/1141257

– Jeff
Nov 27 '18 at 23:31





related: support.mozilla.org/de/questions/1141257

– Jeff
Nov 27 '18 at 23:31













$("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

– TechnoCorner
Nov 27 '18 at 23:31





$("#color_me1") throws null, which is the reason your color is not changing. As others mentioned, it could be the issue with browser or the library not supporting that browser method.

– TechnoCorner
Nov 27 '18 at 23:31













The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

– 97WaterPolo
Nov 27 '18 at 23:44





The color is changing to the hover background color. Default when you select an option it has the text in black and the background white, when using this it just takes the background color of when you hover an option, basically the blue. Is there any workaround or way around this?

– 97WaterPolo
Nov 27 '18 at 23:44












1 Answer
1






active

oldest

votes


















1














Not sure why that happens, but this works:



$("#color_me1").change(function(){
var color = $("option:selected", this).get(0).style.backgroundColor
$("#color_me1").css("background-color", color);
});


Or using JavaScript:



$("#color_me1").change(function(){
var selectedOption = this.selectedOptions[0]
var color = selectedOption.style.backgroundColor
$("#color_me1").css("background-color", color);
});


https://codepen.io/anon/pen/NELLNx






share|improve this answer
























  • Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

    – 97WaterPolo
    Nov 28 '18 at 0:13











  • @97WaterPolo Glad to help!

    – Jaeeun Lee
    Nov 28 '18 at 0:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509716%2fjs-css-code-working-for-chrome-but-not-firefox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Not sure why that happens, but this works:



$("#color_me1").change(function(){
var color = $("option:selected", this).get(0).style.backgroundColor
$("#color_me1").css("background-color", color);
});


Or using JavaScript:



$("#color_me1").change(function(){
var selectedOption = this.selectedOptions[0]
var color = selectedOption.style.backgroundColor
$("#color_me1").css("background-color", color);
});


https://codepen.io/anon/pen/NELLNx






share|improve this answer
























  • Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

    – 97WaterPolo
    Nov 28 '18 at 0:13











  • @97WaterPolo Glad to help!

    – Jaeeun Lee
    Nov 28 '18 at 0:14
















1














Not sure why that happens, but this works:



$("#color_me1").change(function(){
var color = $("option:selected", this).get(0).style.backgroundColor
$("#color_me1").css("background-color", color);
});


Or using JavaScript:



$("#color_me1").change(function(){
var selectedOption = this.selectedOptions[0]
var color = selectedOption.style.backgroundColor
$("#color_me1").css("background-color", color);
});


https://codepen.io/anon/pen/NELLNx






share|improve this answer
























  • Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

    – 97WaterPolo
    Nov 28 '18 at 0:13











  • @97WaterPolo Glad to help!

    – Jaeeun Lee
    Nov 28 '18 at 0:14














1












1








1







Not sure why that happens, but this works:



$("#color_me1").change(function(){
var color = $("option:selected", this).get(0).style.backgroundColor
$("#color_me1").css("background-color", color);
});


Or using JavaScript:



$("#color_me1").change(function(){
var selectedOption = this.selectedOptions[0]
var color = selectedOption.style.backgroundColor
$("#color_me1").css("background-color", color);
});


https://codepen.io/anon/pen/NELLNx






share|improve this answer













Not sure why that happens, but this works:



$("#color_me1").change(function(){
var color = $("option:selected", this).get(0).style.backgroundColor
$("#color_me1").css("background-color", color);
});


Or using JavaScript:



$("#color_me1").change(function(){
var selectedOption = this.selectedOptions[0]
var color = selectedOption.style.backgroundColor
$("#color_me1").css("background-color", color);
});


https://codepen.io/anon/pen/NELLNx







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 0:09









Jaeeun LeeJaeeun Lee

1,13092743




1,13092743













  • Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

    – 97WaterPolo
    Nov 28 '18 at 0:13











  • @97WaterPolo Glad to help!

    – Jaeeun Lee
    Nov 28 '18 at 0:14



















  • Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

    – 97WaterPolo
    Nov 28 '18 at 0:13











  • @97WaterPolo Glad to help!

    – Jaeeun Lee
    Nov 28 '18 at 0:14

















Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

– 97WaterPolo
Nov 28 '18 at 0:13





Thank you very much, this issue kind of threw me off, I appreciate the two different solutions.

– 97WaterPolo
Nov 28 '18 at 0:13













@97WaterPolo Glad to help!

– Jaeeun Lee
Nov 28 '18 at 0:14





@97WaterPolo Glad to help!

– Jaeeun Lee
Nov 28 '18 at 0:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509716%2fjs-css-code-working-for-chrome-but-not-firefox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)