Adding optgroup in select menu
<p>I have a jQuery code which will create <code>select</code> from a <code>ul li menu</code>. I want to add <code>optgroup</code> from parent menu, but don't know how to. Here is my code:</p>

<pre><code>// Create the dropdown base
jQuery("&lt;select /&gt;").appendTo("#module-menu");

// Create default option "Go to..."
jQuery("&lt;option /&gt;", {
    "selected": "selected",
    "value"   : "",
    "text"    : "Go to..."
}).appendTo("#module-menu select");

// Populate dropdown with menu items
jQuery("#menu a").each(function() {
    var el = jQuery(this);
    jQuery("&lt;option /&gt;", {
        "value"   : el.attr("href"),
        "text"    : el.text()
 }).appendTo("#module-menu select");
});
jQuery("#module-menu select").change(function() {
    window.location = jQuery(this).find("option:selected").val();
});
</code></pre>
