I\'m trying to convert (with jQuery) a multi-level UL into a SELECT dropdown with the nested UL group being wrapped in OPTGROUPS
UL
SELECT
OPTGROUPS
// #ShankarSangoli code changed a little var markUp = [""], $li, $a; $("#sitemap > li").each(function() { $li = $(this); if ($li.find("> ul")) { markUp.push(""); $li.find("li").each(function() { $a = $(this).find("a"); markUp.push(""+$a.text()+""); }); markUp.push(""); } else { $a = $li.find("a"); markUp.push(""+$a.text()+"") } }); markUp.push(""); $("#sitemap").replaceWith(markUp.join('')); $("#sitemap").change(function(){ window.location = $(this).val(); });