Hi I am setting a value in a drop down using jquery in the following ways.
$("#dropDownItems option[value='--Select--']").attr('selected', 'true');
$("#dropDownItems option[value='--Select--']").attr('selected', 'selected');
But none of these are working for FireFox! and is working fine for remaining browsers.
Can any one help me out?
This should do the trick for you.
$('#dropdownID').val("Value to be selected");
$("#dropDownItems").val("--Select--");
Or, if you just want to select the first option regardless of its value, you can define this helper function:
$.fn.selectFirst = function () {
return $(this).find("option:first").attr("selected", "selected").end();
}
Then use it like this:
$("#dropDownItems").selectFirst();
If you want to set the default value and it is the first element, you can do:
$('#dropDown')[0].selectedIndex=0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With