I have a list that is generated using some PHP conditional logic in my WordPress theme that outputs categories, example;
<option class="parent"> Parent Category A </option>
<option> Sub Category 1 </option>
<option> Sub Category 2 </option>
<option class="parent"> Parent Category B </option>
<option> Sub Category 1 </option>
<option> Sub Category 2 </option>
I am trying to style each of the parent categories independently of their sub categories so for instance they might be bold or underlined, or even a different font size.
But I am having trouble figuring out how to apply arbitrary styling to items within my select menu because Select2 treats each <option> the same, even stripping out any pre-defined class names or <span> elements which of course is intentional.
Is there an easy way to preserve class names or any HTML tag elements or must it be done via some conditional JavaScript and "formatResults" parameter. If its the latter could you provide a simple example of such?
I'd also like the parent category options within the select menu to be non-selectable, if thats possible too?
Thanks for reading.