Clear dropdown using jQuery Select2 Clear dropdown using jQuery Select2 javascript javascript

Clear dropdown using jQuery Select2


This works for me:

 $remote.select2('data', {id: null, text: null})

It also works with jQuery validate when you clear it that way.

--edit 2013-04-09

At the time of writing this response, it was the only way. With recent patches, a proper and better way is now available.

$remote.select2('data', null)


In case of Select2 Version 4+

it has changed syntax and you need to write like this:

// clear all option$('#select_with_blank_data').html('').select2({data: [{id: '', text: ''}]});// clear and add new option$("#select_with_data").html('').select2({data: [ {id: '', text: ''}, {id: '1', text: 'Facebook'}, {id: '2', text: 'Youtube'}, {id: '3', text: 'Instagram'}, {id: '4', text: 'Pinterest'}]});


This is the proper one, select2 will clear the selected value and show the placeholder back .

$remote.select2('data', null)