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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:47:45+00:00 2026-06-06T16:47:45+00:00

This question is based on my previous question which I got a working answer

  • 0

This question is based on my previous question which I got a working answer to, but only for one slidetoggle element: link

I use the animate method to have the “hidden” elements loaded in the background. Otherwise I could just use slidetoggle, but this leads to a display:none which I don’t want.

So, here’s the function I got so far, but it only runs once for each h2.

HTML:

<h2>Show</h2>
    <div class="content">
        text text text
        <br />
        text text text
        <br />
        text text text
    </div>

<h2>Show</h2>
    <div class="content">
        text text text
        <br />
        text text text
        <br />
        text text text
    </div>

CSS:

.content {
  height: 0;
  overflow: hidden;
}

.heightAuto {
    height: auto;
}​

SCRIPT:

$(function(){  

    $("h2").toggle(function()

     {    
       var $content = $(this).next(".content");
       var contentHeight = $content.addClass('heightAuto').height();
       $content.removeClass('heightAuto');

       $content.removeClass('heightAuto').animate({ height: contentHeight}, 500);

     }, function() {

        $(this).next(".content").animate({ height: "0"}, 500);    

     });
});​

​Could it be a problem to get the height set to auto again? I just can’t find the trick.

Here’s also fiddle: jsfiddle

  • 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-06T16:47:48+00:00Added an answer on June 6, 2026 at 4:47 pm

    Add an extra wrapper which does not get resized:

    <div class="content"><div class="inner">
        text text text
        <br />
        text text text
        <br />
        text text text
    </div></div>
    

    Then use this JS:

    jQuery(function($) {  
        $('h2').toggle(function() {
            var $content = $(this).next('.content');
            $content.animate({ height: $content.find('> .inner').height() }, 500);
        }, function() {
            $(this).next('.content').animate({ height: 0 }, 500);       
        });
    });
    

    EDIT: If you don’t want to use an extra wrapper in your HTML, you can have the JS add a wrapper for you:

    jQuery(function($) {  
        $('h2').toggle(function() {
            var $content = $(this).next('.outer');
            $content.animate({ height: $content.find('> .content').height() }, 500);
        }, function() {
            $(this).next('.outer').animate({ height: 0 }, 500);       
        }).next('.content').wrap('<div class="outer" style="height:0;overflow:hidden"></div>');
    });​
    

    If you use this approach, you should remove your CSS for the .content blocks. See updated fiddle: http://jsfiddle.net/QwmJP/21/

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

Sidebar

Related Questions

This question is based off of the same app/source from my previous question which
Based on answer to my previous question, I would like to ask one more
I'm (sort of) reposting this question, which is based on this previous question: multiple
This is the continuation of my previous question. deleting lines from text files based
In my previous question I got an excellent answer that helped me detect where
I Posted the background to this question a few days ago.. but the answer
This is similar to my previous question, but that solution did not solve this
This question is based on a previous similar question. I have the following equation
As a follow up to this previous question , I have a Core Data-based
I was inspired by this previous question, but I didn't get the whole picture.

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.