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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:16:07+00:00 2026-06-11T18:16:07+00:00

I have a list: <ul class=products> <li class=products p1>first</li> <li class=description p1>first</li> <li class=products

  • 0

I have a list:

<ul class="products">
  <li class="products p1">first</li>
  <li class="description p1">first</li>
  <li class="products p2">second</li>
  <li class="description p2">second</li>
  <li class="products p3">third</li>
  <li class="description p3">third</li>
  <li class="products p4">fourth</li>
  <li class="description p4">fourth</li>
</ul>  

and I want to use jquery to:
1-hide other li s when user clicks on one except the clicked one.
2-show all li s when user clicks again on the active li.
I used the script below:

$(window).load(function(){
$(".products li").click(function(){
     if ($(this).hasClass("active")) {
          $(".products li").show("slow");
          $(this).removeClass("active");
     } else {
          $(this).addClass("active");
          $(".products li:not(.active)").hide("slow");
     }
});
});  

It works fine.
now I want to show the related description li for the active li.
for example if the active li is the li with class:p2, then the below description li needs to be shown and othe li s go hidden:

  <li class="description p2">second</li>  

Description li s are hidden at the beginning.
I dont know how to select the correct li according to class name. There should be a jQuery trick to select li s by class name with mask!

  • 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-11T18:16:08+00:00Added an answer on June 11, 2026 at 6:16 pm

    Add .active class to next li ($(this).next().addClass("active");), and also change selector to li.products because all li are clickable:

    $(window).load(function(){
        $(".products li.products").click(function(){
             if ($(this).hasClass("active")) {
                  $(".products li").show("slow");
                  $(this).removeClass("active");
                  $(this).next().removeClass("active");
             } else {
                  $(this).addClass("active");
                  $(this).next().addClass("active");
                  $(".products li:not(.active)").hide("slow");
             }
        });
    }); ​​
    

    JSFiddle Example

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

Sidebar

Related Questions

I have a list <ul class=products> <li class=products>first</li> <li class=products>second</li> <li class=products>third</li> <li class=products>fourth</li>
I have a Products:List<Product> class. I'd like to make it so that every time
I have List of particular class. I want to save this List at a
i neeed something like this in C#.. have list in class but decide what
I have a list of class object that I created as a variable in
I have a list of class items List<MyClass> I have a seperate object that
I have a list of ProjectItem class instances: List<ProjectItem> allProjects . I need to
I have a list of this class: public class Data { public string name
Let's say I have a list in a class which will be used in
I have the following function defined inside my linked list class. The declaration in

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.