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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:18:26+00:00 2026-05-27T19:18:26+00:00

I have a script that will fetch data from server and compose a DIV

  • 0

I have a script that will fetch data from server and compose a DIV according to it. The DIV will contain image, text and other undetermined content. I want to arrange it freely, so I need to know its height and width before it is shown to the user.

But per my understanding, I should ask browser to render it firstly, otherwise I can’t know the width&height.

Is there any best way to know a DIV’s width&height without showing it to user?

EDIT:

Some good guy suggests that I use jquery’s .width() method, but I am wondering that if the DIV contains image, will jquery wait after the image is downloaded? I don’t know the image’s dimension beforehand.

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

    You can set display: none style on the div. Then use .width() from jQuery and you will get this value.

    For the duration of the calculation it will use .swap() to set style so element is visible, call callback calculating the width and swap style back.

    It will set (see the code):

    • position: absolute
    • visiblity: hidden
    • display: block

    EDIT (see comments):

    If you are loading a image and you want to make sure the image is loaded before you calculate the width then you can attach width calculation as the onload handler like this:

    $('#someImg').load(function() { 
      // image is loaded, you can calculate the width
      console.log($('#test').width())); 
    });
    

    HERE is a working example.

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

Sidebar

Related Questions

I have a PHP script that will generate a report using PHPExcel from data
I'm writing a php script that will fetch data from a given URL and
I have a script that will slide a div up from the bottom of
Ok, so I have the following script that will export data from my database
I have a script that will convert a text file into a resource file,
I have a script that imports a models.py from an app, but it will
I have a script that retrieves objects from a remote server through an Ajax
So I have a script that will allow me to input some text into
I have a php script that fetches data from a DB, the result set
I have a simple PHP script that will either serve up a streaming ASF

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.