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 8302851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:23:18+00:00 2026-06-08T17:23:18+00:00

My vertical nav works except for that when I press on the sibling drop

  • 0

My vertical nav works except for that when I press on the sibling drop down the previous opened drop down does not collapse. I was wondering if you could help me with this.

Here is my javascript code and if you want to look at it in full here is the jsfiddle link: http://jsfiddle.net/CLNBn/2/

$('.vertical-nav ul li:has("div")').find('div').hide();

$('.vertical-nav li:has("div")').find('span:first').click(function() {
    $(this).parent('li').find('span:first').toggleClass("closed opened");
    if ($(this).parent('li').find('span:first').attr('class') == 'closed') {
        $(this).parent('li').find('span:first').text('+');
    } else {
        $(this).parent('li').find('span:first').text('-');
    }
    $(this).parent('li').find('div:first').slideToggle();
});
  • 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-06-08T17:23:19+00:00Added an answer on June 8, 2026 at 5:23 pm

    Since you already gave your elements reasonable classes, this task is quite easy. What you want is to find all span elements with class opened that are children of the siblings of the current li element, and trigger their click event handler.

    This can be done with:

    $(this).closest('li').siblings().children('span.opened').click();
    

    DEMO

    I also took the liberty to simplify your code to:

    $('.vertical-nav li:has("div")').find('span:first').click(function() {
        var $this = $(this);
        $this.toggleClass("closed opened");
        if ($this.hasClass('closed')) {
            $this.text('+');
        } else {
            $this.text('-');
            $this.closest('li').siblings().children('span.opened').click();
        }
        $this.closest('li').find('div').first().slideToggle();
    });​
    

    As I said in my comment, this already refers to the span element, there is no need to traverse up the DOM tree and search for it again.

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

Sidebar

Related Questions

I have designed a 2-Level CSS drop down menu. Everything works perfect except only
The vertical bar does not appear in IE8 if the page is not long
I'm looking for some kind of Nav tab (vertical) that allows it to be
I have a vertical nav menu that is made up of nested lists, however
I have created two menus, a horizontal drop-down and a vertical menu, these both
I am trying to make a menu that works like the one on this
I am writing a web page that has a vertical menu bar on the
I'm using that jQuery Vertical Menu Library www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm I want to accomplish the selection
I have a vertical layout that I want to remain centered on the page.
I have a vertical ul as a nav menu. When a:hover is triggered, a

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.