I'm making a custom select dropdown. I'm trying to convert the options to li elements which works so far. For the conversion I simply use $(selector).each(..). But I want, if they exist inside the select element, convert the opgroups to ul elements and place their options inside of them as li elements.
So to brake it down
If I have:
<select>
<option>
<option>
<option>
</select>
or
<select>
<optgroup>
<option>
<option>
<option>
</optgroup>
</select>
Should become:
<li>
<li>
<li>
or
<ul>
<li>
<li>
<li>
</ul>
How can I achieve this in jQuery? Like I want to have the optgroups as ul only if they are in the select. And the options in the right ul based on their optgroup. My problem right now is that I get all the options in every optgroup (so the same options in every optgroup which is NOT what I want).
*The optgroup should become the ul to which the appropriate options must be appended as li elements.