Reputation: 1779
is there a way to create a select element, but in the middle of the option itens, an option that cant be selected? It would work like a label.
<select>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<!--this one cant be selected -->
<option value="">title</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
Upvotes: 1
Views: 3121
Reputation: 86
You can add a disabled attribute like this
<select>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<!--this one cant be selected -->
<option value="" disabled>title</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
Upvotes: 1
Reputation: 1805
You may used disabled
attribute.
This attribute is a boolean
attribute.
When present, it specifies that an option should be disabled
.
A disabled
option is unusable and un-clickable.
<select>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<!--this option cant be selected -->
<option value="" disabled>title</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
Upvotes: 3
Reputation: 13344
You can set disabled
property on the <option>
element.
<select>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="" disabled="disabled">title</option><!--this one can't be selected -->
<option value="D">D</option>
<option value="E" disabled>E</option><!-- nor this one -->
</select>
Upvotes: 1