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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:47+00:00 2026-05-27T17:56:47+00:00

I am new to jquery.. I’m having to animate a div to a certain

  • 0

I am new to jquery.. I’m having to animate a div to a certain height.. And again on the next click, i need to animate it to height auto. I am able to animate only when i provide the height in px.. here is my code.. can any1 suggest how to find the height of the div on page load.

 $("#photobutton").click(function(){
                          var $text = $("#photobutton").text();

                         if($text == "hide photos") 
                         {
                            $("#photocontainer").animate({height: '144px'}, 1000);
                            $("#photobutton").text("more photos");
                         }
                         else if($text == "more photos")
                         {
                            $("#photocontainer").animate({height: '100%'}, 1000);

                            $("#photobutton").text("hide photos");
                         }

                      });

on the if condition i want the div to collapse to height144px.. and in the else conditions i want the div to stretch to its full height to display all the elements..

  • 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-27T17:56:48+00:00Added an answer on May 27, 2026 at 5:56 pm

    In your second animate() call, assuming you want this div to fill the height of its parent, use:

    $("#photocontainer").animate({height: $("#photocontainer").parent().height()+'px'}, 1000);
    

    EDIT

    1. Example of animating height to fill parent’s height: http://jsfiddle.net/techfoobar/HXjfe/

    2. Example of animating height to fill window’s height: http://jsfiddle.net/techfoobar/C37rs/1/

    EDIT #2

    Animating to auto height: http://jsfiddle.net/techfoobar/psexn/3/

    jQuery’s animate function will not animate to auto height by itself. In fact, it will not animate to any height that cannot be determined prior to the animation.

    We can however get it to do it. But it involves a rather ugly hack. The hack is to hide the div, set height to auto, note the height, revert the height and visibility. Once we have the target height, animate it.

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

Sidebar

Related Questions

Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to
I have application that brings response via Ajax and creates 5-20 new jQuery click
I have a document which uses old jQuery and I need new jQuery for
I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
So I instantiate a new jquery ui dialog window with specified height where the
I'm struggling to determine why the addition of a new jQuery click function is
i m adding new jquery ui tabs to a tab the sample page (click
I am having trouble learning to use the new jQuery Deferred. The does an
I got another question regarding jQuery's architecture. $('div') constructs a new jQuery object: $('div')
When writing a new jQuery plugin is there a straightforward way of checking that

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.