I am trying to convert (with jQuery) a layered UL into a SELECT drop-down menu with a nested UL group wrapped in OPTGROUPS s. I was busy with the idea of ββusing this technique to create custom menu menus (I think dropdown menus).
I have converted list items to a drop-down list of options in the past, but never with optgroups, and I can't figure it out.
An example of my UL structure;
<ul id="sitemap"> <li><a href="www.google.com">Home</a></li> <li><a href="www.google.com">Small Business</a> <ul> <li><a href="www.google.com">Laptops</a></li> <li><a href="www.google.com">Workstations</a></li> <li><a href="www.google.com">Workstations</a></li> <li><a href="www.google.com">Printers</a></li> <li><a href="www.google.com">Mobile Phones</a></li> </ul> </li> <li><a href="www.google.com">Public Sector</a> <ul> <li><a href="www.google.com">State Government</a></li> <li><a href="www.google.com">Federal Government</a></li> <li><a href="www.google.com">Support and Drivers</a></li> </ul> </li> <li><a href="www.google.com">Large Enterprise</a> <ul> <li><a href="www.google.com">Services</a></li> <li><a href="www.google.com">Solutions</a></li> </ul> </li> </ul>
An example of what I have to do
<select id="sitemap"> <option href="www.google.com">Home</option> <optgroup label="Small Business"> <option href="www.google.com">Laptops</option> <option href="www.google.com">Workstations</option> <option href="www.google.com">Printers</option> <option href="www.google.com">Mobile Phones</option> </optgroup> <optgroup label="Public Sector"> <option href="www.google.com">State Government</option> <option href="www.google.com">Federal Government</option> <option href="www.google.com">Support and Drivers</option> </optgroup> <optgroup label="Large Enterprise"> <option href="www.google.com">Services</option> <option href="www.google.com">Solutions</option> </optgroup> </select>
No need to go deeper than one level - and Iβm sure that optgroups really donβt work so well that anyway. Any help you can make would be greatly appreciated. Thanks.
source share