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>
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>
This is not possible with plain html. A few browsers (mozilla) would allow you to achieve something similar using css, but at the time of this writing the majority of browsers (webkit, et.al) do not support styling of html select elements.
However there are a number of javascript libraries designed to enhance html-select widgets and provide missing features such as the one you've requested. To name a few:
Until this is supported in an html standard, any and all answers given have been problematic, including:
This has lead me to conclude the best way to work around the problem is either to use a library like UI-Selectable for all selects throughout your site (for consistency), OR use the first option in the optgroup to represent selecting all the children, with a clear description (such as 'ALL Swedish cars'):
The question is not very clear but is this what you are looking for:
This will give the bare feel of a dropdown list with selectable optgroups. Left it very plain but you can style to your hearts content.
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.
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.
a little different solution..