I am trying to duplicate Expanding Text Areas Made Elegant
Basically it explains how we can achieve something like fb comment box, where its size increases as text files the textarea.
I have this in my index.html:
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="test.css">
    <script src="test.js"></script>
  </head>
  <body>
    <figure>
    <div class="expandingArea">
      <pre><span></span><br></pre>
      <textarea></textarea>
      </div>
      </figure>    
  </body>
</html>
And my test.js looks like:

This doesn't really works. However if I move everything inside the js file to a script tag inside body then it works fine. So my index file would look like:
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="test.css">    
  </head>
  <body>
    <figure>
    <div class="expandingArea">
      <pre><span></span><br></pre>
      <textarea></textarea>
      </div>
      </figure>
 <script>
    function makeExpandingArea(container) {
      var area = container.querySelector('textarea');
      var span = container.querySelector('span');
      if (area.addEventListener) {
      area.addEventListener('input', function() {
      span.textContent = area.value;
      }, false);
      span.textContent = area.value;
      } else if (area.attachEvent) {
      // IE8 compatibility
      area.attachEvent('onpropertychange', function() {
      span.innerText = area.value;
      });
      span.innerText = area.value;
       }
      // Enable extra CSS
      container.className += ' active';
      }var areas = document.querySelectorAll('.expandingArea');
      var l = areas.length;while (l--) {
      makeExpandingArea(areas[l]);
      }
  </script>
  </body>
</html>
 
     
     
    