title: JavaScript: Get window width minus scrollbar width
body: <p>Ok, I thought this would be really simple, but it's turning out not to be.  I think I'm just messing something up in my HTML/CSS, but here goes.</p>
  
  <p>I have a basic page like so:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;link href='test2.css' rel="stylesheet" type="text/css" /&gt;
      &lt;script src="http://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
      &lt;script src="test2.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="scroll"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>test2.css</strong></p>
  
  <pre><code>* {
    padding: 0;
    margin: 0;
  }
  
  html, body {
    height: 100%;
    width: 100%;
  }
  
  #scroll {
    height: 100%;
    width: 100%;
    overflow: scroll;
    background-color: black;
  }
  </code></pre>
  
  <p><strong>test2.js</strong></p>
  
  <pre><code>$(document).ready(function() {
    // my resolution is 1440x900
    alert('innerwidth should be 1425');
    // all of these return 1440
    alert('body innerwidth: ' + $('body').innerWidth());
    alert('document width: ' + $(document).width());
    alert('window width: ' + $(window).width());
    alert('scroll div innerwidth: ' + $('#scroll').innerWidth());
    alert('document.documentElement.clientWidth: ' + document.documentElement.clientWidth);
    alert('document.documentElement.scrollWidth: ' + document.documentElement.scrollWidth);
  });
  </code></pre>
  
  <p>So I've got one element on the page... a div that takes up the entire screen, or rather it should be taking up the entire screen minus the scrollbars.  Now, I've been doing some snooping on how to grab the width and height of a page without the scrollbars, but unfortunately, none of them return the proper value... which makes me believe I'm missing the boat in my HTML or CSS.</p>
  
  <p>I looked at the following:</p>
  
  <p><a href="https://stackoverflow.com/questions/8339377/jquery-how-to-get-screen-width-without-scrollbar">jquery - how to get screen width without scrollbar?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8221341/how-to-get-the-browser-window-size-without-the-scroll-bars">how to get the browser window size without the scroll bars</a></p>
  
  <p>So what I need is for a method to return the value of my viewable screen minus the respective scrollbar value... so for my width, my value should be 1425 because the scrollbar is 15 pixels wide.  I thought that's what innerWidth's job was, but apparently I'm wrong?</p>
  
  <p>Can anyone provide any insight?  (I'm running Firefox 24.)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>To add some background, I've got a blank page.  I will be adding elements one by one to this page, and I need to use the width of the page when calculating the sizes for these elements.  Eventually, this page will grow and grow until the scrollbar appears, which is why I'm trying to force the scrollbar there from the start, but apparently, that still doesn't do anything.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Here's something even more interesting... if I do <code>document.getElementById('scroll').clientWidth</code>, I get the proper innerWidth, but if I do <code>$('#scroll').width()</code> or <code>$('#scroll').innerWidth()</code>, they both return the max resolution... sounds like a jQuery bug.</p>