html - Making optgroup label as selected in dropdown -
i planning put brief description page main car type (swedish cars). want show volvo , saab under swedish cars in dropdown. when click on volvo, should navigate volvo description page. how can show optgroup label selected initially?
thank you.
<select> <optgroup label="swedish cars"> <option value="volvo">volvo</option> <option value="saab">saab</option> </optgroup> </select>
i believe asking render this:
this not strictly possible can't "select" option group label. effect you're looking you'll have perform bit of trickery.
we can put custom label span
, absolutely position span on select
make initial selection appear option group label. after need little bit of javascript fake click
, change
event, can see working example below. however, html look:
<div class="select-wrapper"> <span>swedish cars</span> <select> <optgroup class="swe-car" label="swedish cars"> <option value="volvo">volvo</option> <option value="saab">saab</option> </optgroup> </select> </div>
Comments
Post a Comment