I want to add class to option in select2, so after i click on suggest list item it will add custom class added-to-select-multiple to the main select structure.
Here's example code:
<select id="myselect2" multiple="multiple" style="width:50%;">
<option>One</option>
<option>Another option</option>
<option>Hello there</option>
</select>
After i click on first element of suggest list :
_________HTML output from inspect___________________
<select id="myselect2" multiple="" style="width:50%;" data-select2-id="myselect2" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true">
// result
<option data-select2-id="4" class="added-to-select-multiple">One</option>
<option data-select2-id="5">Another option</option>
<option data-select2-id="6">Hello there</option>
</select>
How to achive that? I was experimenting with :
$('#myselect2').trigger({
type: 'select2:select',
});
but i haven't found the solution, i think i wasn't even close.
Fiddle: https://jsfiddle.net/Friiz/19rootn5/1/
Thanks for any help!