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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:30:43+00:00 2026-06-04T06:30:43+00:00

Given a div that has a scrollbar in it (e.g. b/c of overflow:auto), how

  • 0

Given a div that has a scrollbar in it (e.g. b/c of overflow:auto), how do I get the accurate innerWidth of the element? In my example: http://jsfiddle.net/forgetcolor/2J7NJ/ width and innerWidth report the same width. The number I want should be less than 100.

HTML:

<div id='box1'>
<div id='box2'>
</div>
</div>
<p id="w"></p>
<p id="iw"></p>​

CSS:

#box1 { 
    width:100px;
    height:100px;
    overflow:auto;
}

#box2 {
    width:200px;
    height:200px;
    background-color:#aaa;
}

Javascript:

$('#w').text("width is: "+$('#box1').width());
$('#iw').text("inner width is: "+$('#box1').innerWidth());​

Update:

I need this to work when the box2 div contains a large image (thus, takes a second to load). Here’s an example, integrating one of the solutions below (Lukx’), that doesn’t work: http://jsfiddle.net/forgetcolor/rZSCg/1/. Any ideas how to get it to wait for the image to load before calculating the width?

  • 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-06-04T06:30:44+00:00Added an answer on June 4, 2026 at 6:30 am

    By inserting a new DIV into the #box1-Container, this DIV will obtain the available width – and reading its width returns a value that appears to be correct.

    HTML and CSS both remain unchanged

    JS Becomes

    var helperDiv = $('<div />');
    $('#box1').append(helperDiv);
    
    $('#iw').text("inner width is: " + helperDiv.width());
    helperDiv.remove();​​​​​​​​​​​​​​​​​​​​​​​​​​​ // because we dont need it anymore, do we?
    

    I also forked your Fiddle to see what I have done: http://jsfiddle.net/xc9xQ/2/

    So to get this value with a function:

    function widthWithoutScrollbar(selector) {
      var tempDiv = $("<div/>");
      $(selector).append(tempDiv);
      var elemwidth = tempDiv.width();
      tempDiv.remove();
      return elemwidth;
    };
    
    //Example
    console.log($('#page').width());  // 1280
    console.log(widthWithoutScrollbar('#page'));  // 1265
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
Given this div : <div style=overflow:auto;></div> How can I make the scrollbars visible only
I have a div that has been given a tabindex, when the div is
Given a webpage that has a div such as: <div id=test class=test>something</div> Is it
Here is my script: http://jsfiddle.net/9cnGC/11/ <div id=callus> <div class=def>111-1111</div> <div class=num1>222-2222</div> <div class=num2>333-3333</div> <div
Given that I have a button within a div: <div id=result> <a href='#task5'> <img
So I have this Div that has a roll over effect on it where
Given an HTML page that has a complex table-based layout and many tags that
I'm using a third party javascript that has given me a lot of need
The web designer has given me HTML which looks like: <div .... style=background: transparent

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.