Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:57:57+00:00 2026-05-30T04:57:57+00:00

I have a UL LI menu that I am turning into a select dropdown

  • 0

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/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:57:58+00:00Added an answer on May 30, 2026 at 4:57 am

    This should do what you want, and it’s pretty customizable. http://jsfiddle.net/C5S32/7/

    var options = '<option selected>Go to...</option>';
    $('#primary-nav').find('a').each(function () {
        var text = $(this).text(),
            depth = $(this).parent().parents('ul').length,
            depthChar = '',
            i = 1;
        for (i; i < depth; i++) { depthChar += '&ndash;&nbsp;'; }
        options += '<option>' + depthChar + text + '</option>';
    });
    $('<select />').append(options).appendTo('#primary-nav');
    

    As a side note, in your code you’re appending stuff many times. It’s better to append everything in one call to avoid excessive reflows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a menu that will have its menu items injected into it
I have a menu div that I want to slide down so it's always
I have a popup menu that has a few items in it. Option 1
I want to have a menu that when I click replaces the content of
I have a dropdown menu that works fine, but I would like it so,
I have a select menu that displays countries. It looks at the DB and
I have a menu that lets you select color schemes, but i can only
I have a menu that scrolls down and will let you select what color
I need to have a menu that has items that size themselves based on
I have a menu that comes up for my PreferenceActivity. In my child preference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.