Skip to content
Advertisement

Resetting Select2 value in dropdown with reset button

What would be the best way to reset the selected item to default? I’m using Select2 library and when using a normal button type="reset", the value in the dropdown doesn’t reset.

So when I press my button I want “All” to be shown again.

jQuery

$("#d").select2();

html

<select id="d" name="d">
  <option selected disabled>All</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

Advertisement

Answer

I’d try something like this:

$(function(){
    $("#searchclear").click(function(){
        $("#d").select2('val', 'All');
    });
});
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement