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>
select2 tags set value jquery
$('#mySelect').select2({
data: ['one','two'],
tags: true
});
$('#mySelect').val(['one','two']).trigger('change')
get select2 selected value jquery
$('#id :selected').text();
Source:stackoverflow.com
select2 replace options
select2 dropdown with option to add new item
$('#select2')
.select2()
.on('select2:open', () => {
$(".select2-results:not(:has(a))").append('<a href="#" style="padding: 6px;height: 20px;display: inline-table;">Create new item</a>');
})
Source: stackoverflow.com