Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display optgroup label as initial option [closed]

Tags:

html

css

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.

like image 236
hcharge Avatar asked Mar 05 '13 13:03

hcharge


People also ask

How do I hide Optgroup labels?

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.

Can Optgroup be selected?

From Select2 docs: "Furthermore, <optgroup> elements cannot be made selectable.

What does Optgroup tag mean?

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.

Is used to select only one option from given group of options *?

Answer. Check box, Multiselect.


Video Answer


1 Answers

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.

like image 148
BenM Avatar answered Sep 18 '22 08:09

BenM