Search code examples
jqueryinternet-explorerselected

how to set an option being selected by jquery in ie?


I try to set an option being selected via its value.My code is out here.It works in FF and Chrome but not in IE.can anyone help me?

var province = $("#hideProvince").val();
if(province != ""){
  $("#province option[value='"+ province + "']").attr("selected", "selected");
}

Solution

  • Try attr("selected", true) instead of attr("selected", "selected"), I found this post it may be related to what you are looking for.

    var province = $("#hideProvince").val();
    if(province != ""){
      $("#province option[value='"+ province + "']").attr("selected", true);
    }