thanks, everything is fine within safari, opera and internet explorer. within firefox, the container's background color is not changing yet. as background color firefox (osx) chooses preconfigured systemcolor, not the one specified in the option-fields style-sheet. bug in firefox?!
On 21 Apr., 04:01, James <james.gp....@gmail.com> wrote: > Is there a reason you're running a $.each for the selected option? It > seems there's only one possible selected option at once. > > $("select").change(function() { > $selected = $(this).find("option:selected"); > $("#result").css( 'background-color', $selected.css > ("background-color") ); > $(".foo").text( $selected.text() ); > }); > > On Apr 19, 8:30 pm, "geh...@googlemail.com" <geh...@googlemail.com> > wrote: > > > 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>