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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:41:33+00:00 2026-06-08T06:41:33+00:00

I want to add the active class to all the main category block in

  • 0

I want to add the active class to all the main category block in my html code as follows:-

<ul class="tabs">

   <li class="accordion"><a href="#tab1">Boo1</a>

           <ul id="sub-nav">
              <li><a href="http://www.myweb.com"> Ipsum Text</a></li>
              <li><a> Lorem text</a></li>
              <li><a> More lorem text </a></li>
              <li><a> Dolor Sit Amet </a></li>
           </ul>                                   

  </li> 


  <li><a href="#tab2">Boo2</a></li>
  <li><a href="#tab3">Boo3</a></li>
  <li class="last-item"><a href="#tab4">Boo4</a></li>

</ul>​

styled this way:-

#sub-nav  > .active {background:#AAA;}
.tabs li a.active { background: green; }
.tabs li a {font-size:20px;}
#sub-nav li a {font-size:16px; margin-left:20px;}

​

so I did this:-

(function(){
    $('.tabs #sub-nav li').bind('click', function(e){
        var subNavList   = $(this),
            list = $('.tabs').find('li').add('.tabs a');
            list.removeClass('active');  


        subNavList.addClass('active').parents('li').addClass('active').children('a').addClass('active');
    });
}());​

my only problem now is when the other nav list is clicked (boo2 and boo3), the active class is not applied. Please check the jsfiddle code to understand better. http://jsfiddle.net/gfkM4/6/ What am I doing wrong guys? Can some please help me out?

  • 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-08T06:41:35+00:00Added an answer on June 8, 2026 at 6:41 am

    I believe this is what you are looking for (select the top nav when clicked also select both the subnav and it’s parent when clicked):

    http://jsfiddle.net/gfkM4/9/

    (function(){
    
        $('.tabs a').on('click', function(e){
            $('.tabs a').removeClass('active');
            $(this).addClass('active');
            $(this).closest('ul').closest('li').children('a').addClass('active');
        })       
    
    }());​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HTML: <div class=tabbed-section> <ul class=tabs> <li><a href=#tab-1>Tab 1</a><li> <li><a href=#tab-2>Tab 2</a><li> </ul> <div id=tab-1
I am running a Jcarousel and I want to add a.active to the current
I want add my custom sidebar next right column all page. Please check this
I want to list all the records from DB, which are all active(true) in
I have this $(document).ready(function() { //Default Action $(.tab_content).hide(); //Hide all content $(ul.tabs li:first).addClass(active).show(); //Activate
The setting is easy; I want to be able to add a class to
I want to add three toggle functions on one page (all with the same
I have the following HTML: <ul> <li class=one><a href=#>one</a></li> <li class=two><a href=#>two</a></li> <li class=three><a
I want add UIGestureRecognizerDelegate to UIWebView,but failed. if [self.view addsubView:webView]; So UIWebView is ok,but
I want add new Feed item on entity persist and update. I write this

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.