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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:49:25+00:00 2026-06-12T16:49:25+00:00

Can someone tell me what I’m doing wrong here. Trying to remove/add class attribute

  • 0

Can someone tell me what I’m doing wrong here. Trying to remove/add class attribute to li so that correct one is active when clicked: http://jsfiddle.net/cyberpuunk/D2RLR/2372/

<div class="container">        
          <div class="span8">
              <ul class="nav nav-tabs gallery-nav">
                <li class="active">
                  <a href="#"<strong>All</strong></a>
                </li>
             <li><a href="#"><strong>link1</strong></a></li>
           <li><a href="#"><strong>link2</strong></a></li>
             </ul>
              </div>
   <div class="row">
       <div class="span12">
           <div class="page1">qwer</div>
            <div class="page1">asdf</div>
            <div class="page1">zxcv</div>
       </div>  
    </div>    
</div>

$('.page1:gt(0)').hide();

$('ul.gallery-nav li').click(function(e) {
    e.stopPropagation();
    var liIndex = $(this).index();
    $('.page1').hide().eq(liIndex).show();
    $(this).removeClass("active");
    eq(liIndex).addClass("active");
}); // end click
  • 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-12T16:49:26+00:00Added an answer on June 12, 2026 at 4:49 pm
    $('ul.gallery-nav li').click(function(e) {
        e.stopPropagation();
        $('.page1').hide().eq($(this).index()).show();
        $('ul.gallery-nav li').removeClass("active");
        $(this).addClass("active");
    });
    

    Fiddle

    You had a syntax error at

    eq(liIndex).addClass("active");
    

    .eq() is a jQuery object method and not a function that you can on its own. That could be fixed by using $('ul.gallery-nav li').eq(liIndex).addClass("active"); BUT there would would be still a logic flaw:

    $(this).removeClass("active");
    

    You’re supposed to add instead of remove the class, as this references the clicked li and not the whole group of list items which you’re attaching the handler to. With that said, the fixed version of your code is:

        $('ul.gallery-nav li').removeClass("active");
        $(this).addClass("active");
    //as $(this) references the clicked li, you don't need $('ul.gallery-nav li').eq(liIndex)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me what i am doing wrong here? I want the boxes
can someone tell me what i am doing wrong here.. i am not getting
Can someone tell me what I am doing wrong here: function onAjaxDone(data) { var
Can someone tell me what I'm doing wrong here and how to make the
Can someone tell me what I'm doing wrong to package this as a module:
Can someone tell me what's wrong with this code? I'm trying to upload a
Can someone tell me how can I select the Row under the one on
Can someone tell me why this is not working: <button class=btn danger id=delete onclick=return
Can someone tell me what's wrong with this http://jsfiddle.net/Yp8Bz/ ? It works fine in
Can someone tell me how to add easing to this plugin. I understand there's

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.