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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:53:16+00:00 2026-06-13T23:53:16+00:00

I am making a dropdown menu and am trying to make the list items

  • 0

I am making a dropdown menu and am trying to make the list items image change from a plus (when not opened) to a minus (when opened).

The first Tier (parent list items) are set to list-style:none; so when the .click() below executes, I want the .addClass('close'); to apply to everything EXCEPT the parent <li>‘s…

The issue is, the selector used in the encompassing .click() function includes the parent list items.

What I need to do is say:

“Apply the class ‘close’ to $(this) EXCEPT the first (parent) <li>‘s'”

Here is the jQuery:

$(document).ready(function(){

  $("#nav li").click(function(event){

    // My attempt (not working)...
    $(this).not("#nav > ul > li").addClass('close');

    event.stopPropagation();
    $(this).children("ul").slideToggle(100);

    $(".last, a").click(function(event){
      event.stopPropagation();
    });

  });

});

And the jsFiddle:

Click to View

So my attempt was the following:

$(this).not("#nav > ul > li").addClass('close');

That didn’t work… So if anyone has any advice, it would be greatly appreciated! thanks 🙂

Update:

The class ‘close’ needed !important added to it. The jQuery was doing what it should. I will post an answer when I successfully remove the class upon closing the menu item.

Update (2):

Removed !important and changed class specification to #nav li.close. Thanks Adeneo!

Update (3):

Changed .addClass() to .toggleClass(). Seems to make this menu do what I wanted it to 🙂 Thanks Sushanth — for this suggestion!

  • 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-13T23:53:17+00:00Added an answer on June 13, 2026 at 11:53 pm

    Your problem is not being specific enough with the css selector.

    using #nav li is more specific than just .close, to fix the problem use #nav li.close (not !important) :

    #nav li.close {
        list-style-image:url(http://www.horsepowerfreaks.com/images/close.gif);
    }
    

    FIDDLE

    Here’s a little more on CSS specificity and inheritance

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

Sidebar

Related Questions

I'm making a webapp for iOS. When I make a dropdown list with the
i am trying to implement jquery's toggle method to make a dropdown menu, it
I am trying to build a fancy jquery dropdown menu ,while making the menu
hi i'm making a dropdown menu, but there is a problem with ie7, sub-list's
I'm making a dropdown menu and it's working perfectly with the slideUp/slideDown functions from
I'm making a CSS dropdown menu. So, when the mouse hovers one menu item,
I'm making a pure css dropdown menu (code here: http://jsfiddle.net/SeXyv/7/ ) and I would
I'm on the process of making a dropdown widget. The menu the expands down
I am making a dropdown menu on one of my menu item. ie: |
I want to insert a value from the database into my dropdown menu in

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.