jQuery change selected option's background on change of selected item

Posted by Scott B on Stack Overflow See other posts from Stack Overflow or by Scott B
Published on 2010-03-17T12:51:54Z Indexed on 2010/03/17 14:21 UTC
Read the original article Hit count: 335

Filed under:

I have a routine that dynamically changes a select list's "selected" option when the corresponding image from a carousel widget is clicked (it's a wordpress template selector).

I'd just like to add a flash of background color, then fade to white, to give the user a visual cue that they've just changed the value of the template chooser select list.

I've attempted at it below to assign the className "mySelectedOption" to the selected option, but its not working.

I'm sure there is perhaps a better way to get the visual cue I'm looking for, (since the css change is static and wont fade back to white background)

$('#carousel ul li').click(function(e) {
    var myOption = $(this).children('img').attr('title');
    $("#myTheme option[value='"+myOption+"']").attr('selected', 'selected');
    $("#myTheme :selected]").attr('className', 'mySelectedOption');

    });

© Stack Overflow or respective owner

Related posts about jQuery