title: Javascript CreateElement button
body: <p>I have a problem I been suffering on for a couple hours now.
  The context is, I need to make a button with action listener in JavaScript and add it into a table.</p>
  
  <p>Here is the code I have</p>
  
  <pre><code>var _button = document.createElement("button");
  _button.data = _a;
  _button.innerHTML = 'click me';
  _button.onclick = function()
  {
      alert("hello, world");
  }
  
  var table = document.getElementById("tableOnline");
  var row = table.insertRow(1);
  var cell1 = row.insertCell(0);
  var cell2 = row.insertCell(1);
  var cell3 = row.insertCell(2);
  
  var _weakbutton = _button.outerHTML;
  _weakbutton.onclick = function()
  {
      alert("hello, world");
  }
  
  cell1.innerHTML = "h";
  cell2.innerHTML = "o";
  cell3.innerHTML = _weakbutton;
  </code></pre>
  
  <p>The code works if I add the create the button and add it onto the body (without weakButton), but how can I make it work into a table?</p>
  
  <p>Kind regards,
  Zhendos.</p>
  
  <p>EDIT:
  Because requested, here is the table we talk about.</p>
  
  <pre><code>&lt;div class = "container"&gt;
   &lt;div class = "table"&gt;
    &lt;thead id = "thead"&gt;
     &lt;tr&gt;
      &lt;th&gt; firstname &lt;th&gt;
      &lt;th&gt; lastname &lt;/th&gt;
      &lt;th&gt; organisation &lt;/th&gt;
     &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
  
    &lt;/tbody&gt;
   &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>