To set selected value of jQuery Select2 with JavaScript, we call val
and then trigger
.
For instance, we write
$("#drpServices").select2().val("0").trigger("change");
to create the drop down with
$("#drpServices").select2()
Then we set its value with the val
method to the option with value attribute set to 0.
Finally, we call trigger
with 'change'
to update the drop down to show the value we set.