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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:05:54+00:00 2026-06-16T03:05:54+00:00

Guys Im just stuck in this, Giving an active class. its just simply not

  • 0

Guys Im just stuck in this, Giving an active class. its just simply not working for me – I will show the code, it may let you help me faster. I know the Jquery logic behind the theory but in practical its just NOT done anyway. Thats the reason I came over to ask that.
Its there on http://jsfiddle.net/j08691/dZ9KP/12/ .

<div id="MainContainer">
  <ul id="MainNav">
    <li> <a href="#page1">   title 1  </a>     </li>
    <li>    <a  href="#page2">  title 2 </a>     </li>                
  </ul>
  <div id="MainContent">
    <div class="MainContentEach" id="page1">
      title 1 content
    </div>
    <div class="MainContentEach" id="page2">
      title 2 content
    </div>
  </div>
</div>

JS

     $(function () {
        $('#MainNav a').click(function () {
        pageId = $(this).attr('href');
        num = $('#MainNav a').index(this);
        $(pageId).parent().animate({ scrollTop: (500 * num) }, 'slow');
        });
      });

Any help would be appreciated.

  • 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-16T03:05:56+00:00Added an answer on June 16, 2026 at 3:05 am

    If you only need to add a class called active to the <a> tag when its clicked you could do something like this:

    $(function () {
        $('#MainNav a').click(function () {
             pageId = $(this).attr('href');
             num = $('#MainNav a').index(this);
             $(pageId).parent().animate({ scrollTop: (500 * num) }, 'slow');
    
             $('#MainNav a').each(function () {
                 if ($(this).hasClass('active')) {
                     $(this).removeClass('active');
                 }
             });
    
             if (!$(this).hasClass('active')) {
                 $(this).addClass('active');
             }
        });
    });
    

    This will add a class called active your <a> tag, keep in mind this class will need to be defined in your stylesheet.

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

Sidebar

Related Questions

Hey guys this should be simple, I'm just not seeing it, I would like
Hey guys - I'm stuck with this problem and im just wondering what the
Hey guys, I'm doing an ASP.NET MVC project just for learning...and stuck in this...
Guys I know this question is silly but just to make sure: Having in
How do you guys write comments on some simple code that you use just
Ok guys, let me preface my question with this, This is not a technical
I am stuck looking and debugging this code and I can't see any errors.
Guys back to being stuck with my sql layout on my tables, I just
Hey guys i've been stuck on this problem for 2 days in a row,
This should be fairly simple, but it's just not loading for me. Here's my

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.