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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:57:23+00:00 2026-05-21T04:57:23+00:00

An easy one, but I can’t figure it out. I have a link called

  • 0

An easy one, but I can’t figure it out. I have a link called #title and when you click it it toggles div called #content. This works perfectly, but in addition I’m adding “active” class to my #title link and I can’t get rid of it, even with removeClass.

See code above and example link (the title should be red ONLY when the #content is expanded, not all the time).

$('#title').click(function() {
    $(this).addClass('active');
    $('#content').toggle();
}), function() { 
    $(this).removeClass('active');
};

http://jsfiddle.net/vY3WY/

  • 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-05-21T04:57:23+00:00Added an answer on May 21, 2026 at 4:57 am

    You can use the toggleClass function along with toggle.

    http://jsfiddle.net/vY3WY/1/

    $('#title').click(function() {
        $(this).toggleClass('active');
        $('#content').toggle();
    });
    

    Or you can use a more robust version which will ensure that the class is added if the content is visible and removed otherwise.

    http://jsfiddle.net/vY3WY/6/

    $('#title').click(function() {
        $('#content').toggle();
        if ($('#content:visible').size() != 0)
        {
             $(this).addClass('active');   
        }
        else
        {
             $(this).removeClass('active');   
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like it should be an easy one but I can't figure it
I would have thought this would be an easy one to Google, but I've
This must be an easy one but I can't find documentation for it online.
This should be an easy one, but I can't find a good example anywhere.
This is an easy one, I am sure, but I can't seem to find
Easy one to explain. Is there any way I can do this: <div id=header
Ok I have a question and it is probably very easy but I can
I'm sure this one is easy but I've tried a ton of variations and
This one has me puzzled. It seemed like an easy task, but the solution
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;

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.