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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:43:00+00:00 2026-05-14T22:43:00+00:00

Ok, I was going to answer someone’s question here on SO about why their

  • 0

Ok, I was going to answer someone’s question here on SO about why their script wasn’t working. They loaded content into a hidden div, then got the height so they could animate the wrapping div. But I always try to test the code I provide. So I made this demo to prove it to them.

So, umm, have I entered the twilight zone or am I dreaming right now? pinches self OUCH!

I tried that demo in Firefox, IE and Chrome and both methods return the same value. Firebug says zero! I rebooted my computer and I even changed the code a bit (removed the height function) and tried it with jQuery 1.3.2 and it still worked! I know hidden elements USED to return a zero value. Even this SO Answer is giving the advice I would have!

So I guess my question is… did I miss something or are we giving bad advice?

  • 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-14T22:43:01+00:00Added an answer on May 14, 2026 at 10:43 pm

    Looking at the jQuery 1.4.2 and 1.3.2 source code, it actually performs this automatically when you call width() or height() on a hidden element. It sets the following attributes:

    { position: "absolute", visibility: "hidden", display:"block" }
    

    Then it gets the width/height, and restores the old values of the attributes.

    So there is no need to change the attributes yourself – jQuery will handle it for you.

    <Edit>
    This will allow you to get the dimensions of a hidden element. However, it won’t work when the element is contained within another hidden element – you’ll get a height of 0. In that case you’d need another solution, possibly like this answer.
    </Edit>


    Here are the relevant bits of the source code from 1.4.2:

    cssShow = { position: "absolute", visibility: "hidden", display:"block" },
    
    //[undocumented jQuery.css function which is called by .height() and .width()]
    css: function( elem, name, force, extra ) {
        if ( name === "width" || name === "height" ) {
            var val, props = cssShow, ....
    
            function getWH() {
                ... this function gets the actual width/height into the variable val
            }
    
            if ( elem.offsetWidth !== 0 ) {
                getWH();
            } else {
                jQuery.swap( elem, props, getWH );
            }
    
            return Math.max(0, Math.round(val));
        }
        return jQuery.curCSS( elem, name, force );
    },
    
    // A method for quickly swapping in/out CSS properties to get correct calculations
    swap: function( elem, options, callback ) {
        var old = {};
    
        // Remember the old values, and insert the new ones
        for ( var name in options ) {
            old[ name ] = elem.style[ name ];
            elem.style[ name ] = options[ name ];
        }
    
        callback.call( elem );
    
        // Revert the old values
        for ( var name in options ) {
            elem.style[ name ] = old[ name ];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping someone could answer my quick question as I am going nuts!
I'm going to answer my own question here because I spent a few hours
I was going to ask a question here about whether or not my design
I was going to post an answer on this other SO question but someone
I have a surprisingly basic question; I thought the answer was going to be
somehow I am going in circles here. Please forgive me if the answer to
Simple question, the answer may not be... I'm going to be developing a web
I sweated over the question above. The answer I'm going to supply took me
Asked the same question here but got no answer, so I'm trying here instead
I had this question about arrays in JavaScript. I couldn't really find an answer.

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.