Search code examples
jquerybuttondrop-down-menuclick

How do I clear the dropdownlist values on button click event using jQuery?


How do I clear the dropdownlist values on button click event using jQuery?


Solution

  • A shorter alternative to the first solution given by Russ Cam would be:

    $('#mySelect').val('');
    

    This assumes you want to retain the list, but make it so that no option is selected.

    If you wish to select a particular default value, just pass that value instead of an empty string.

    $('#mySelect').val('someDefaultValue');
    

    or to do it by the index of the option, you could do:

    $('#mySelect option:eq(0)').attr('selected','selected'); // Select first option