title: Keep the footer at the bottom with Javascript
body: <p>At the moment I'm trying to keep the footer at the bottom with Javascript. This is the result:</p>
  
  <pre><code>document.getElementsByTagName('body').onload = function() {KeepFoot()};
  var element = document.getElementById('container');
  var height = element.offsetHeight;
  
  function KeepFoot() {
      if (height &lt; screen.height) {
          document.getElementById("footer").style.position = "fixed";
          document.getElementById("footer").style.bottom = "0";
          document.getElementById("footer").style.left = "0";
          document.getElementById("footer").style.right = "0";
      }
  }
  </code></pre>
  
  <p>My idea was to take the height of the div container and compare it with the height of the resolution of the pc. If the height of the div container is smaller than the height of the resolution of the PC, set to the div footer <code>position: fixed;</code></p>
  
  <p>But there is a problem in the script because it doesn't work.</p>
  
  <p>Another question, the script that I created would be fine for keep the footer at the bottom?</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          ...
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="container"&gt;
              &lt;div id="header"&gt;&lt;/div&gt;
              &lt;div id="content"&gt;&lt;/div&gt;
              &lt;div id="footer"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>