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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:10:33+00:00 2026-05-12T17:10:33+00:00

Suppose I have the following html, and no CSS <div> here is some content

  • 0

Suppose I have the following html, and no CSS

<div> 
  here is some content in this div. it stretches it out
  <br />and down too!
</div>

Now I want to get the actual pixel width and height that the browser has rendered this div as.

Can that be done with JS?

Thank you.

  • 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-12T17:10:33+00:00Added an answer on May 12, 2026 at 5:10 pm

    Try getting a reference to your div and reading the offsetWidth and offsetHeight properties:

    var myDiv = document.getElementById('myDiv');
    var width = myDiv.offsetWidth; // int
    var height = myDiv.offsetHeight;
    

    offsetWidth/Height cumulatively measures the element’s borders, horizontal padding, vertical scrollbar (if present, if rendered) and CSS width. It’s the pixel values of the entire space that the element uses in the document. I think it’s what you want.

    If that is not what you meant, and you’d rather only the element’s width and height (i.e. excluding padding, margin, etc) try getComputedStyle:

    var comStyle = window.getComputedStyle(myDiv, null);
    var width = parseInt(comStyle.getPropertyValue("width"), 10);
    var height = parseInt(comStyle.getPropertyValue("height"), 10);
    

    The values above will be the final, computed pixel values for the width and height css style properties (including values set by a <style> element or an external stylesheet).

    Like all helpful things, this won’t work in IE.


    You say you are using jQuery. Well it’s trivial now, and works cross-browser:

    var width = $('div').css('width');
    var height = $('div').css('height');
    

    With jQuery you don’t need the first part of this answer, it’s all taken care of for ya 😉

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

Sidebar

Related Questions

I have the following file: <html> <head> <title></title> <link rel=css type=text/css href=/empty.css title=css />
I have the following HTML and CSS: <button id=myBtn dojoType=dijit.form.Button>Testing</button> #myBtn { margin-left: 100px;
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
For so long, I've read and understood the following truths concerning web development: HTML
Can somebody please explain this IE7 bug to me? It occurs in Standards and
What's the best way to use <input type=radio> in HTML? I'm looking for HTML
This is a question about Qt library, not about Web design. For QLabel and
On the first click, it works as expected: the class is changed and the
I'm working on a web application that uses ASP.NET 3.5 and C#. Structurally, I

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.