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:

enter image description here

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> 

https://jsfiddle.net/atbqtnq8/


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -