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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:54:40+00:00 2026-06-15T12:54:40+00:00

Ok, somehow I’m just not able to figure out how to make this work,

  • 0

Ok, somehow I’m just not able to figure out how to make this work, it can’t be that difficult.

I have a plain old navigation, like so:

<ul>
        <li><a href="#" class="men-trigger">Men's</a></li>
        <li><a href="#" class="women-trigger">Women's</a></li>
        <li><a href="#" class="coed-trigger">Coed</a></li>
        <li><a href="#" class="all-trigger">All</a></li>
</ul>

And I need to add a class to the clicked element (which I know how to do):

$('.men-trigger').click(function() {  
   $(this).addClass('active');   
});

What I’m having problems with is how to remove the class active from a nav item when another nav item is clicked.

I’ve tried something like but it doesn’t work:

$('.men-trigger').click(function() {  
    $(this).addClass('active');
    $(this).prev().siblings().find('active').removeClass('active');
});

I’ve tried using .parent().siblings().children();, .parents(ul).find('active'); and I still haven’t been able to make it work.

I created a Demo of this.

NOTE: Each nav element needs to have its own class because I’m doing something else in the script, here I’m just showing you the problem I’m having.

Thanks in advance for any help on this.

  • 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-15T12:54:41+00:00Added an answer on June 15, 2026 at 12:54 pm
    $('.men-trigger').click(function() {  
        $(this).addClass('active').siblings().removeClass('active');
    });
    

    Also, you can join all those function with the “ends-with” selector:

    $('[class$="trigger"]').click(function() {  
        $(this).addClass('active').siblings().removeClass('active');
    });
    

    And since they are nested anchors inside li’s, you’ll probably have to to:

    $('[class$="trigger"]').on('click', function() {  
        $(this).addClass('active').parent('li').siblings().find('a').removeClass('active');
    });​
    

    which also adds on() as the preferred way to bind event handlers if using jQuery 1.7+

    FIDDLE

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

Sidebar

Related Questions

Somehow, my code does not work. I can't figure out why, I'm completely new
Somehow I can't see to make it work.. I'm trying to send the picture
Somehow I'm having a brainfart and can't figure out proper big and little endian
Somehow this doesn't work... var paper = Raphael(test, 500, 500); var testpath = paper.path('M100
Somehow I managed to make the date work, <td width=67><font size=3><b>*Date</b></td> <td width=3>:</td> <td
Somehow am not successful with creating the query that I want. DB is to
Somehow I feel really silly to ask this question, but I just spent 2
Somehow a variable that SHOULD contain only one string (not an array or anything)
somehow I'm doing hard to figure out the difference between #import <Cocoa/Cocoa.h> and #import
Somehow this does not feel like the culmination of the 50 years programming language

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.