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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:01:01+00:00 2026-06-09T06:01:01+00:00

Fiddle: http://jsfiddle.net/vuKqw/60/ What would allow the ‘active’ class to remain attached to an item

  • 0

Fiddle: http://jsfiddle.net/vuKqw/60/

What would allow the ‘active’ class to remain attached to an item when it is clicked twice? The intended behavior is that only whe a NEW tab is clicked does it change classes. Otherwise, if the same tab is clicked twice for example, it should remain ‘active’ not toggle between active and inactive.

$('nav li a').click(function() {
    $(this).parent().toggleClass('active').siblings().removeClass('active');
});

Reference: Jquery change class on click menu


I ended up breaking it out into a function:
http://jsfiddle.net/vuKqw/72/

function tabchange() { 
 var parent = $(this).parent();
    if(!parent.hasClass('active')) {
        parent.addClass('active').siblings().removeClass('active');
}
};

$('nav li a').click(tabchange)​

Thank you @Madbreaks for the answer- that pointed me in the right direction.

  • 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-09T06:01:03+00:00Added an answer on June 9, 2026 at 6:01 am

    Check first to see if the parent is active:

    $('nav li a').click(function() {
        var parent = $(this).parent();
        if(!parent.hasClass('active')){
            parent.addClass('active').siblings().removeClass('active');
        }
    });
    

    Note the use of ‘addClass’ instead of ‘toggleClass’ – better to be more specific in situations where you know exactly what you’re doing (the intent there is only ever to add the class).

    Cheers

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

Sidebar

Related Questions

Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
This is best explained with a Fiddle: http://jsfiddle.net/hxsJx/ I want to add a class
Fiddle: http://jsfiddle.net/8TxmK/ I have two divs, one which has class=bb and another with no
Please see the fiddle ( http://jsfiddle.net/Jk6Bk/5/ ) I would like to add some spacing
Fiddle: http://jsfiddle.net/TKWzH/8/ The Test Pop is the current function of the item. Test Pop
Fiddle: http://jsfiddle.net/amitava82/dawkn/6/ The input elements will be generated dynamically based on json data received
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have this fiddle: http://jsfiddle.net/yub2B/4/ HTML: <input type=text /> <input type=text /> <input type=text
In this fiddle http://jsfiddle.net/dAHqe/2/ I've created examples for the 2 main uses (that I've
This is the fiddle: http://jsfiddle.net/36mdt/ After about 10-20 seconds, the display starts to freeze

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.