I have a UL LI menu that I am turning into a select dropdown when you're viewing it on a mobile.
I want to now indent child items e.g
- List item 1
- -- Child item 1
- ---- Child Child item 1
- -- Child item 2
- List item 2
Rather than listing in one single line.
I'm happy to just add nbsp to keep things easy - or add classes and CSS if more suitable.
The code I am currently using to generate the select is:
$("<select />").appendTo("#primary-nav");
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo("#primary-nav select");
$("#primary-nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("#primary-nav select");
});
$("#primary-nav select").change(function() {
window.location = $(this).find("option:selected").val();
});
The menu it is generating from is built like:
<ul>
<li><a>Item 1</a>
<ul>
<li><a>Child Item 1</a>
<ul>
<li><a>Child Item 1</a></li>
</ul>
</li>
<li><a>Child Item 2</a></li>
</ul>
</li>
<li><a>Item 2</a></li>
</ul>
Here is a fiddle with an example: http://jsfiddle.net/C5S32/