[jQuery] select change function
hello everybody,
i'm new in jquery (and javascript).
ive try to write a little function to change the background-color for
an element.
it can change the text but not the background-color.
any help?
-----------jQuery---------------
$("select").change(function() {
var bar = "";
var foo = "";
$("select option:selected").each(function() {
bar += $(this).text();
foo += $(this).css("background-color");
});
$("#result").css('background-color', foo);
$(".foo").text(bar);
}).change();
-------- HTML -------------------
<select name="id[1]">
<option style="background-color:#ff0000;">red</option>
<option style="background-color:#00ff00;">green</option>
<option style="background-color:#0000ff;">blue</option>
</select>
<div id="result">element with new background-color</div>