Hi Having this check box:
<select id="events"> <option value="1" style="background-color:green;">Event 1</option> <option value="2" style="background-color:yellow;">Event 2</option> <option value="3" style="background-color:blue;">Event 3</option> <option value="4" style="background-color:red;">Event 4</option> </select>
In the initial browser rendering version of this selection and every time the selection is done , I want the βeventsβ of the selection to display the background color of the selected option.
How can this be achieved through jquery or through regular javascript?
//Alert color on initial page load var bkg = $("#events option:selected").css("background-color"); alert(bkg); //Handle change event and alert color when selection is done $(function(){ $("#events").change(function() { var bkg = $("#events option:selected").css("background-color"); alert(bkg); }); });
selected
$('#events').bind('change', function() { var bgc = $(this).find('option:selected').css('background-color'); });
:
$("#events").change(function() { $(this).css("backgroundColor", $(this).find(":selected").css("backgroundColor") ); }).change();
. , , IE. <select>, , (- ... ). , , , . , , - .
<select>
IE, option.
option
$(this).html($(this).html());
Source: https://habr.com/ru/post/1778283/More articles:Sql instead of insert trigger - insert data if it does not exist - sqlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1778279/how-to-get-all-parent-and-child-categories-that-each-product-belongs-to&usg=ALkJrhgftsKj2qYkv7rrHFXXRbLISSzDjgUse a mechanism to access an authenticated HTTP web page - pythonTracking command history of multiple ksh sessions - linuxLZMA or 7zip in Delphi - delphiproblem with Mongoid ordering - sortingChange filter in Silverlight Pivot Viewer to use AND instead of OR - silverlightPHP: programmatically submit a form and get the contents of the summary page? - phpPublish a text area with cURL - phpOpening a Word document (.doc) from a stream - streamAll Articles