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

  • Home
  • SEARCH
  • 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 7946947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:17:32+00:00 2026-06-04T01:17:32+00:00

HTML: <div id=bottomContent class=bottom_content > <p>First Content</p> </div> <div id=bottomContent2 class=bottom_content > <p>second Content</p>

  • 0

HTML:

<div id="bottomContent" class="bottom_content" > <p>First Content</p> </div>

<div id="bottomContent2" class="bottom_content" > <p>second Content</p> </div>

<div id="bottomContent3" class="bottom_content" > <p>Third Content</p> </div>

JS:

   $("div.one").click (function(){
      $("#bottomContent2").hide();
      $("#bottomContent3").hide();
      $("#bottomContent").animate({width: "toggle"}, 1000);
    });

    $("div.two").click (function(){
       $("#bottomContent").hide();
       $("#bottomContent1").hide();
       $("#bottomContent2").animate({width: "toggle"}, 1000);
    });

    $("div.three").click (function(){
       $("#bottomContent").hide();
       $("#bottomContent2").hide();
       $("#bottomContent3").animate({width: "toggle"}, 1000);
    });

I have the following jQuery code whereby when each of the divs is clicked, it will animate its own corresponding div item and close any other div that may be already opened but I am sure there are better ways to code it and make it more compact than I have done. Any help will 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-04T01:17:33+00:00Added an answer on June 4, 2026 at 1:17 am

    I always approach this problem by putting some extra metadata (using data-* attributes) on the element being clicked to associated it’s content:

    <div class="action" data-content="#bottomContent">
      Click me for bottom content
    </div>
    <div class="action" data-content="#bottomContent1">
      Click me for bottom content 1
    </div>
    <div class="action" data-content="#bottomContent2">
      Click me for bottom content 2
    </div>
    

    Notice ive also given all three div’s the same class, enabling me to associate the same action with all three.

    Then the jQuery becomes:

    $("div.action").click (function(){
        var $this = $(this);
    
        $('div.action').not($this).each(function(){
           var $other = $(this);
           var otherTarget = $other.data('content');
           $(otherTarget).hide();       
        });
    
        var target = $this.data('content');        
        $(target).animate({width: "toggle"}, 1000);
    
    });
    

    Live example: http://jsfiddle.net/rHKML/

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

Sidebar

Related Questions

I've this piece of HTML: div.content div.one content div.two content div.three content I want
$(function() { var div = $('div'); $('input').click(function() { if($(this).is(':checked')) { div.html(div.text() += 49); }
I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have four HTML div I want to show and hide them on click
Suppose the following HTML div container <div id=container> <form> <div> <label class=error>Name</label> <input type=text
How can I obtain this structure with HTML div 's? The first div on
My HTML looks like and js looks like this: <div class=container></div> var html =
I've a HTML div and I want to hide it whenever the user clicks
How would I hide a HTML div when the browser window is either maximized
I am going to display the Flexigrid in html div tag when click a

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.