Select2 is a jQuery plugin that customizes HTML select element and makes it more user-friendly.
It adds search features and allows to add an image with options.
The HTML select element option can easily set selected using jQuery – $(selector).val(option-value);
.
But this does not directly work with the Select2 dropdown element.
In this tutorial, I show how you can dynamically set an option selected in Select2 with jQuery.