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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:16:13+00:00 2026-05-27T02:16:13+00:00

I have multiple divs called .details , and I want to apply the following

  • 0

I have multiple divs called .details, and I want to apply the following click functions to them. But right now if I click on one li, all li’s with the same class names change throughout all the divs called .details. How do I only apply the click function to the current .details div?

$(document).ready(function() {
    $('.details div.two').hide();
    $('.details div.three').hide(); 

    $('.details ul li.one').click(function () { 
        $(this).addClass('active');
        $('.details ul li.two').removeClass('active');
        $('.details ul li.three').removeClass('active');
        $('.details div.one').show();
        $('.details div.two').hide();
        $('.details div.three').hide(); 
    });
    $('.details ul li.two').click(function () { 
        $(this).addClass('active');
        $('.details ul li.one').removeClass('active');
        $('.details ul li.three').removeClass('active');
        $('.details div.one').hide();
        $('.details div.two').show();
        $('.details div.three').hide(); 
    });
    $('.details ul li.three').click(function () {   
        $(this).addClass('active');
        $('.details ul li.one').removeClass('active');
        $('.details ul li.two').removeClass('active');
        $('.details div.one').hide();
        $('.details div.two').hide();
        $('.details div.three').show(); 
    });
});

HTML

<div class="details">
    <ul>
        <li class="one active"><span>Nav 1</span></li>
        <li class="two"><span>Nav 2</span></li>
        <li class="three"><span>Nav 3</span></li>
    </ul>
    <div class="one">
        <p>Content 1</p>
    </div>
    <div class="two">
        <p>Content 2</p>
    </div>
    <div class="three">
        <p>Content 3</p>
    </div>                                                                          
</div>                          

CSS

.active {background:#fff;}
  • 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-27T02:16:14+00:00Added an answer on May 27, 2026 at 2:16 am

    Go back to the top with closest and then come back down with find:

    $('.details ul li.one').click(function () { 
        $(this).closest('.details')
               .find('ul li').removeClass('active').end()
               .find('div.two, div.three').hide().end()
               .find('div.one').show();
        $(this).addClass('active');
    });
    

    Similarly for the other two.

    You could further clean things up with a bit of generalization and then you’d only need one .click call instead of three; something like this.

    $('.details ul li').click(function () {
        var $this    = $(this);
        var $details = $this.closest('.details');
        var idx      = $details.find('li').index(this);
        $details.find('ul li').removeClass('active').end()
                .find('div:not(:eq(' + idx + '))').hide().end()
                .find('div:eq(' + idx + ')').show();
        $(this).addClass('active');
    });
    

    Demo: http://jsfiddle.net/ambiguous/2zYt3/

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

Sidebar

Related Questions

I have multiple divs like setted up below. I want 1 (one) JQuery function
i have a screen with multiple little widgets (all with different divs around them).
I have an html page with google maps in one of the divs called
I have have multiple divs' with similar code within it, but also has a
this is kinda tricky to explain,but here goes....I have multiple hidden divs that swap
i have a div containing multiple divs with absolute position, i want to handle
I have multiple divs on my page.I want to copy selected text from div1
I have multiple divs (haveing same class names). I want to move the div
ok, So I have multiple divs(7) which I want to toggle for show hide.
I hope I can word this okay. I have multiple divs all called '.collapse-conten'

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.