Is there any way to make the option group selectable?
<select> <optgroup value="0" label="Parent Tag"> <option value="1">Child Tag</option> <option value="2">Child Tag</option> </optgroup> </select>
From Select2 docs: "Furthermore, <optgroup> elements cannot be made selectable.
The <optgroup> tag is used to group related options in a <select> element (drop-down list). If you have a long list of options, groups of related options are easier to handle for a user.
Use the <select> tag to create a selectable list. The HTML <select> tag is used within a form for defining a select list. Specifies that on page load the drop-down list should automatically get focus.
I don't think you can but you can easily reproduce the visual style with css and thus only have options in your select, so everything is selectable.
.optionGroup { font-weight: bold; font-style: italic; } .optionChild { padding-left: 15px; }
<select multiple="multiple"> <option value="0" class="optionGroup">Parent Tag</option> <option value="1" class="optionChild">Child Tag</option> <option value="2" class="optionChild">Child Tag</option> </select>
The multiple attribute allow you to select more than one row (with ctrl click). You can remove it if it is not what you want. It was to show you that everything became selectable and that is looking the same as with optiongroup element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With