Answers for "set selected option jquery select2"

4

select2 clear options

Remove the selected options : 
-----------------------------
$('#mySelect2').val(null).trigger('change');

============================================

Completly remove the select2 initialization :
--------------------------------------------
$('#payment_method').html('').select2({data: [{id: '', text: ''}]});
Posted by: Guest on July-30-2020
2

jquery select2 set value

<select id="lang" >
   <option value="1">php</option>
   <option value="2">asp</option>
   <option value="3">java</option>
</select>

<script>
	$("#lang").select2().select2('val','1');
</script>
Posted by: Guest on May-10-2021
2

select2 tags set value jquery

$('#mySelect').select2({
  data: ['one','two'],
  tags: true
});
$('#mySelect').val(['one','two']).trigger('change')
Posted by: Guest on July-31-2021

Code answers related to "set selected option jquery select2"

Browse Popular Code Answers by Language