Try to change SELECT color
Hello,
I'm just starting using JQUERY so I excuse myself whether my question is too much trivial. The following code is just a sample test.
I'm trying to change the color of a SELECT control after selecting one of its options. For example, when I select "red" I'd like to change the SELECT control to "red". But I do not know how to do.
However, I think I have first to get the selected option properties. That is what I'm trying to achieve.
It is OK for value and text, but not for RGB. I was expecting to receive rgb(255,0,0) instead of getting something else which is obviouly wrong. .
Thanks a lot in advance for any help (and sorry for my bad English).
Gege
- <html><head>
- <meta http-equiv="Content-type" content="text/html; charset=Windows-1252"/>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function()
- {
- $("#S1").mouseup(function()
- {
- var txt = $("#S1 option:selected").text();
- var val = $("#S1 option:selected").val();
- var rgb = $("#S1 option:selected").css('backgroundColor');
- alert("Text = " + txt + " Value =" + val + " --> " + rgb);
- });
- });
- </script></head><body>
- <center><p><h1>Test JQUERY
- <h2>
- <form><select id='S1' style='background-color:#25F0FF;'>
- <option value='0' style='background-color:#25F0FF;' >Light Blue</option>
- <option value='1' style='background-color:#0000FF;' >Blue/option>
- <option value='2' style='background-color:#FF0000;' >red</option>
- <option value='3' style='background-color:#00FF00;' >Green</option>
- <option value='4' style='background-color:#000000;' >Black</option>
- </select>
- </body></html>
-