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
JavaScript
x
2
1
$("#d").select2();
2
html
JavaScript
1
7
1
<select id="d" name="d">
2
<option selected disabled>All</option>
3
<option value="1">1</option>
4
<option value="2">2</option>
5
<option value="3">3</option>
6
</select>
7
Advertisement
Answer
I’d try something like this:
JavaScript
1
6
1
$(function(){
2
$("#searchclear").click(function(){
3
$("#d").select2('val', 'All');
4
});
5
});
6