javascript - jquery: select options and background color -
greetings, having such select 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> at initial browser render of selectbox , each time selection done, want selectbox "events" background-color of selected option.
how can achieved via jquery or via regular javascript ?
//alert color on initial page load var bkg = $("#events option:selected").css("background-color"); alert(bkg); //handle change event , alert color when selection done $(function(){ $("#events").change(function() { var bkg = $("#events option:selected").css("background-color"); alert(bkg); }); });
Comments
Post a Comment