Is it possible to show the label of an optgroup in a select dropdown as the first option?
Does this make sense? Or is there a better way to do it?
I basically need a first label that shows like Select Price and that isn't directly selectable, but shows when you expand the select menu like an optgroup label does.
The hidden attribute hides the <optgroup> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <optgroup> element is not visible, but it maintains its position on the page.
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.
Answer. Check box, Multiselect.
You can use a standard option
element and simply specify the disabled
attribute:
<select>
<option disabled="disabled" selected="selected">Select Price</option>
<optgroup label="Gold">
<option>5.00</option>
<option>10.00</option>
</optgroup>
</select>
See this jsFiddle demo.
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