jqueryinternet-explorer-8html-select

Selecting option in a list not working in IE


I'm trying to set an option in a list as selected, but the following code is not working in IE8 (works in FF). Does anybody know why (or know a workaround)?

$('select option[value="'+image+'"]').attr('selected', 'selected');

Solution

  • Which version of jQuery do you use in your project?

    I think from 1.6 on, you should be able to do

    $('#my_select').val('some_value');
    

    EDIT: As @ThiefMaster pointed out, this is not version dependent:

    http://jsfiddle.net/bscJ2/