title: Apply JS onto table, which is created after page is loaded
body: <p>I have got an html page, where you can put text into a textarea, click a button and then it creates an html table. 
  Problem is, that i am using a JS file to make my table sortable, but this JS file is not applied to tables that are created after the page itself is created. 
  How can i call the JS file again after the button is clicked and the table created? Or is there any other way to apply the JS file to the new table? </p>
  
  <p>My problem seems to be like this problem: 
  <a href="https://stackoverflow.com/questions/20617477/apply-jquery-propieties-on-new-element-created-after-the-page-is-loaded">Apply jquery propieties on new element created after the page is loaded</a>
  But i can't use JQuery, is there any way without it? </p>
  
  <p>Example for a created table: </p>
  
  <pre><code>&lt;div id="artikelnr2"&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
  
  
  &lt;link rel="stylesheet" type="text/css" href="table.css"&gt;
  &lt;script src="java.js"&gt;&lt;/script&gt;
  
          &lt;div class="datagrid"&gt;&lt;table class="sortable"&gt;
          &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Nummer&lt;/th&gt;&lt;th&gt;Nummer&lt;/th&gt;&lt;th&gt;Bezeichnung&lt;/th&gt;&lt;th&gt;Bemerkungen&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
          &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;897-251&lt;/td&gt;&lt;td&gt;00.702.07803.7&lt;/td&gt;&lt;td&gt;5G2&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;897-1051&lt;/td&gt;&lt;td&gt;00.702.0306.7&lt;/td&gt;&lt;td&gt;5G1&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;897-1651&lt;/td&gt;&lt;td&gt;00.702.0307.3&lt;/td&gt;&lt;td&gt;5G1U&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;897-341&lt;/td&gt;&lt;td&gt;00.702.0323.9&lt;/td&gt;&lt;td&gt;5G2.5&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;/tr&gt;
          &lt;/tbody&gt;
          &lt;/table&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I am using sorttable.js from this page:
  <a href="http://www.kryogenix.org/code/browser/sorttable/" rel="nofollow noreferrer">http://www.kryogenix.org/code/browser/sorttable/</a></p>
  
  <p>JavaScript which is called after button is clicked (pastes the content of another page into an exisiting div container):</p>
  
  <pre><code>    function getOutput(url) {  
  var file = selectedValue()+".csv";
  var value = document.getElementById("artikelnr").value;
  &lt;!---Leerzeichen entfernen--&gt;
  value = myTrim(value); 
  var url = url || "verarbeitung.php?eingabe="+value+"&amp;eingabe2="+file ; 
  
    getRequest(
        url, // URL for the PHP file
         drawOutput,  // handle successful request
         drawError    // handle error
    );
    return false;
  }
  
  // handles drawing an error message
  function drawError() {
      var container = document.getElementById('artikelnr2');
      container.innerHTML = 'Bummer: there was an error!';
  }
  // handles the response, adds the html
  function drawOutput(responseText) {
      var container = document.getElementById('artikelnr2');
      container.innerHTML = responseText;
      tempResult = responseText; 
  }
  // helper function for cross-browser request object
  function getRequest(url, success, error) {
      var req = false;
      try{
          // most browsers
          req = new XMLHttpRequest();
      } catch (e){
          // IE
          try{
              req = new ActiveXObject("Msxml2.XMLHTTP");
          } catch(e) {
              // try an older version
              try{
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              } catch(e) {
                  return false;
              }
          }
      }
      if (!req) return false;
      if (typeof success != 'function') success = function () {};
      if (typeof error!= 'function') error = function () {};
      req.onreadystatechange = function(){
          if(req.readyState == 4) {
              return req.status === 200 ? 
                  success(req.responseText) : error(req.status);
          }
      }
      req.open("GET", url, true);
      req.send(null);
      return req;
  }
  </code></pre>