Reset select2 value and show placeholder Reset select2 value and show placeholder jquery jquery

Reset select2 value and show placeholder


You must define the select2 as

$("#customers_select").select2({    placeholder: "Select a customer",    initSelection: function(element, callback) {                       }});

To reset the select2

$("#customers_select").select2("val", "");


The accepted answer does not work in my case. I'm trying this, and it's working:

Define select2:

$("#customers_select").select2({    placeholder: "Select a State",    allowClear: true});

or

$("#customers_select").select2({    placeholder: "Select a State"});

To reset:

$("#customers_select").val('').trigger('change')

or

$("#customers_select").empty().trigger('change')


Select2 has changed their API:

Select2: The select2("val") method has been deprecated and will be removed in later Select2 versions. Use $element.val() instead.

The best way to do this now is:

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

Edit: December 2016 Comments suggest that the below is the updated way to do this:

$('#your_select_input').val([]);