title: scrollbar management of a 'div' with javascript or jquery
body: <p>Is there a way to control a scrollbar's life depending on the browser size and the 'div' size at the same time in javascript or jquery. For example, if the 'div' content is overflowing then add scrollbar to div and if the browser is resized to a higher height then remove scrollbar from div, since it's gonna be stretched with the browser:</p>
  
  <pre><code>$("#wrapper").height($(window).height() - 215);
  
  var elem = document.getElementById("topPanel");
  var errHolder = document.getElementById("error");
  
  if(elem.scrollHeight &gt; elem.clientHeight - errHolder.scrollHeight){
      $(elem).css({
                  "overflow-y": "auto",
                  "overflow-x": "hidden",
                  height: elem.scrollHeight - errHolder.scrollHeight
                  });
  }
  
  $(window).resize(function(e){
      if(this.clientHeight &gt; 200){
          $(elem).css({
                      "overflow-y": "auto",
                      "overflow-x": "hidden",
                      height: "200px"
                      });
      }
      else {
          $(elem).css({
                  "overflow-y": "auto",
                  "overflow-x": "hidden",
                  height: elem.scrollHeight - errHolder.scrollHeight
                  });
      }
  });
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>#toolPanel {
  position: relative;
  width: 100%;
  height: 100%;
  }
  
  #topPanel {
  overflow: auto;
  height: 315px;
  width: 100%;
  background: #069;
  border: 1px solid #0CC;
  }
  
  #bottomPanel {
  position: absolute;
  background: #0CC;
  border: 1px solid #069;
  height: 65px;
  width: 100%;
  bottom: 0;
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div id="wrapper"&gt;
    &lt;div id="toolPanel"&gt;
      &lt;div id="error"&gt;&lt;/div&gt;
      &lt;div id="topPanel"&gt;
          &lt;!-- Content that may overflow --&gt;
      &lt;/div&gt;
      &lt;div id="bottomPanel"&gt;&amp;nbsp;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is just a head-start but I'm lost... I'm not good with the use of clientHeight/scroll, offset, etc. Please help.</p>