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

The Archive Base Latest Questions

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

So I have an image that I need to call .width and .height but

  • 0

So I have an image that I need to call .width and .height but I’m running into the old problem with IE returning 0 if any of the parent elements are not visible.

Because of the dynamic nature of this particular task, it’s not possible to tell at design time which elements will be visible. So my solution to this is to take my image element and then go up the element hierarchy one parent at a time and set it to visible if it isn’t. I’m going to add the element id to an array if I set it to visible so I know which ones to flip back to hidden after I get the width/height.

So my question is: how do I write a recursive jQuery function go up the element tree and check if the element is hidden or not?

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

    No need for any recursion, you can do that much easier:

    var hiddenElements = $(yourelement).parents().filter(':hidden').show();
    

    Instead of .filter(':hidden') you could also use .not(':visible') – but that’s just a matter of style.


    However, why not simply do it like this – it will avoid annoying flickering of elements which would be shown for a short moment just to be hidden again. Besides that, the image is already cached so cloning it will not cause any noticable delays (or any additional network traffic).

    var clone = $(yourelement).clone().appendTo('#dummy');
    // now get the size
    clone.remove();
    

    To prevent the clone from being flickering into visiblity, style #dummy like this:

    #dummy { position: absolute; left: -1000em; }
    

    This will hide it without actually making it invisible.

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

Sidebar

Related Questions

So here's my issue. I have an image that I need to shrink. The
I have a container that contains an image that I need to drag from
Basically what the title says... I need to have an image that when clicked,
I have a slow connection that I need to send a PNG image over
I have a BufferedImage with an IndexColorModel. I need to paint that image onto
Situation: I have a simple XML document that contains image information. I need to
I have this method that changes an larger image source on click. I need
I have some images that need to change, based not only on hover, but
I have an action that returns a Dynamically Generated image however I need the
I have a variable for the background-image attribute of an element that I need

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.