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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:39:24+00:00 2026-05-16T15:39:24+00:00

I always thought elements that had display:none CSS style returned 0 for height() and

  • 0

I always thought elements that had display:none CSS style returned 0 for height() and width().

But in this example:

HTML

<div id="target" style="display:none;">
a
</div>

CSS

alert($("#target").height());

they don’t: http://jsfiddle.net/Gts6A/2/

How come? I’ve seen 0 come back plenty of times in the past.

  • 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-16T15:39:24+00:00Added an answer on May 16, 2026 at 3:39 pm

    If an element has an offsetWidth of 0 (jQuery is considering this “hidden”), checked here, then it attempts to figure out what the height should be. It sets the following properties on the element via jQuery.swap() for the duration of the check:

    • position: "absolute"
    • visibility: "hidden"
    • display: "block"

    Then it gets the height, via getWidthOrHeight(...) which adds border/padding if necessary via augmentWidthOrHeight(...) depending on the box model, and reverts all of the above properties to their former values.

    So basically it’s taking the element, showing it out of the flow of the document, getting the height, then hiding it again, all before the UI thread updates so you never see this happen. It’s doing this so .height()/.width() works, even on elements that are currently hidden, as long as their parents are visible…so you can run .height()/.width(), without doing the show/hide trick it’s doing in your code, it’s handled within .height() and .width().

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

Sidebar

Related Questions

I've always thought that F# had two different ways to pass arguments, curry style
I always thought that parentheses improved readability, but in my textbook there is a
I always thought that *&p = p = &*p in C. I tried this
I used to just use p and span elements for this... but I'm always
I always thought that jQuery operates only on DOM elements , that is those
I thought I had a solid plan to do this but somehow or the
I always thought that you could use OR in a LIKE statment to query
I always thought they were about the same thing but someone pointed me out
I always thought that if you didn't implement a heartbeat, there was no way
I always thought that when you dropped a control onto an .aspx page 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.