Change Text Color of Selected Option in a Select Box

前端 未结 6 1761
南笙
南笙 2020-12-02 22:54

I have a select box. The options have been styled with different colors via a CSS file that has been referenced. I want to be able to select an option and change the text co

6条回答
  •  情书的邮戳
    2020-12-02 23:43

    JQuery Code:

    $('#mySelect').change(function () {
        $('#mySelect').css("background", $("select option:selected").css("background-color"));
    });
    

    This will replace the select's background-color with selected option's background-color.

    Here is an example fiddle.

提交回复
热议问题