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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:40:26+00:00 2026-06-07T01:40:26+00:00

I need a little help to get my side nav working properly. Link to

  • 0

I need a little help to get my side nav working properly.

Link to my working version: http://recx.vaughndtaylor.com/

Notice that the nav expands/contracts properly, but I want to have the +/- acting independent of the link. For example, I want the menu to expand when the + is clicked, but I want the link to go to a page.

I’m using Google’s side nav as an example: https://developers.google.com/chart/

The toggle in this example can be clicked, but you can also click the link.

This is what I have:

 $('li.openable').click(function(){
        if ($(this).children('div.accordion').is(':hidden')) {
            $(this).siblings().removeClass('active').children('div.accordion').slideUp();
            $(this).toggleClass('active').children('div.accordion').slideDown('fast');
        } else {
            $(this).removeClass('active').children('div.accordion').slideUp('fast');
        }
        return false;
    });

I think I need something more like this:

$('li.openable > span.icon').click(function(){
    if ($(this).children('div.accordion').is(':hidden')) {
        $(this).siblings().removeClass('active').children('div.accordion').slideUp();
        $(this).toggleClass('active').children('div.accordion').slideDown('fast');
    } else {
        $(this).removeClass('active').children('div.accordion').slideUp('fast');
    }
    return false;
});

I’m having difficulties figuring out the relationship between objects here. In my second example, $(this) is no longer the correct object (this is now span.icon). Do I set this as a variable? Do I use relationships (eg. siblings(), parents()?)

Any help on this issue would be greatly appreciated.

Thanks!

Update: This is how I resolved the issue using the suggestion below:

$('li.openable > span.icon').click(function(){
        var expander = $(this).parents('li');
        if (expander.children('div.accordion').is(':hidden')) { 
            expander.siblings().removeClass('active').children('div.accordion').slideUp(); 
            expander.toggleClass('active').children('div.accordion').slideDown('fast'); 
        } else {
            expander.removeClass('active').children('div.accordion').slideUp('fast');
        }
        return false;
    });
  • 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-07T01:40:28+00:00Added an answer on June 7, 2026 at 1:40 am

    You said the right thing. Make a variable based on the parent() of the span element and go from there:

    $('li.openable > span.icon').click(function(){
        var thingToExpandOrContract = $(this).parents('li');
    
    ...
    

    Go from there using the variable instead of “this”.

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

Sidebar

Related Questions

I need a little help here: I get a file from an HTML upload
Hi I need a little help: How to get profile URL given an UID?
I would need little help here. I'm trying to get the git respository from
I need a little help with navigating a json file. I'm looking to get
I need little help for url rewriting in wordpress. basically what i need: mydomain.com/mysomewordpresspost
I need a little help setting up a HTTP Post in C#. I appreciate
I need a little more help to get how a DI framework like Ninject
I have some JQuery that isn't working and I need a little help. I
need a little help with some sql. I am trying to get distinct frompersonid,
I need a little help consolidating my code. This is the working code but

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.