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

  • SEARCH
  • Home
  • 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 5954595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:59:36+00:00 2026-05-22T17:59:36+00:00

The purpose of this element is to have a collapsible navigation system based entirely

  • 0

The purpose of this element is to have a collapsible navigation system based entirely from a simple unordered list. By default all nested lists will be hidden, and .toggle divs (buttons) attached to li items that contain a nested list. These .toggle divs should then hide/show the nested list as well as apply a class to the toggle button.

I’ve tested this code by manually inserting the .toggle div (location noted with [toggle div]), and everything works perfectly. When it’s added through append() though, nothing seems to work. Does anyone know what might be causing this problem? Any help would be greatly appreciated – thanks!

HTML:

<div id="nav">
<ul>
<li><a href="#">nav item</a>[toggle div]
    <ul>
        <li><a href="#">nav item</a></li>
        <li><a href="#">nav item</a></li>
        <li><a href="#">nav item</a>[toggle div]
            <ul>
                <li><a href="#">nav item</a></li>
                <li><a href="#">nav item</a></li>
                <li><a href="#">nav item</a></li>
            </ul>
        </li>
        <li><a href="#">nav item</a></li>
    </ul>
</li>
<li><a href="#">nav item</a></li>
<li><a href="#">nav item</a></li>
<li><a href="#">nav item</a></li>
</ul>
</div>

jQuery:

$(function(){
$("#nav ul li").has("ul").append("<div class='toggle'></div>");
$(".toggle").live("click", function() {
    if($(this).next().is(":hidden")) {
        $(this).next().show();
        $(this).addClass("toggled");
    } else {
        $(this).next().hide();
        $(this).removeClass("toggled");
    }
});
});
  • 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-22T17:59:36+00:00Added an answer on May 22, 2026 at 5:59 pm

    Try this:

    $("#nav li > ul").before('<div class="toggle"></div>');
    

    If will select all <ul> elements which are directly nested in <li> elements, and adds the <div> in front of each of them.

    Have a look at the demo: http://jsfiddle.net/xXRSZ/1/

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

Sidebar

Related Questions

I can very well understand from this Selectutorial what element/tag based descendant selectors are,
[purpose] This simple command sequence runs expected in the Windows' CMD shell: dir &
The purpose of this code is to pull upgrade.zip from a central server, extract
I created a simple speech recognition service: for this purpose I created a subclass
I am developing an accessible app. For this purpose it is important that all
I have read the documentation for this element but still fail to understand what
What is the purpose this and why this be added when we add new
EDIT: Purpose of this Website: Its called Utopiapimp.com. It is a third party utility
My whole purpose of this is to get something looking like this: I want
What kind of tools or techniques exist for this purpose?

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.