title: delete row in table with javascript
body: <p>Apologies if something similar has been posted but I am trying to delete a row the button is on and not just the last row as the search results seem to give me.</p>
  
  <p>I have the following code that adds to an HTML table but <code>onclick</code> doesn't work, the delete button doesn't work and addRow doesn't function. Why not? </p>
  
  <p><strong>java code</strong></p>
  
  <pre><code>function addRow() {
  
    var table = document.getElementById("createOrderTable");
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
  
    ... other cells ...
  
    var cell4 = row.insertCell(3);
    var btn = document.createElement("input");
    btn.type = "button";
    btn.value = "Close";
    btn.onclick = deleteRow('createOrderTable', rowCount);
    cell4.appendChild(btn); 
  
  }
  
  function deleteRow(id, row) {
    document.getElementById(id).deleteRow(row);
  }
  </code></pre>
  
  <p><strong>table code</strong></p>
  
  <pre><code>&lt;table id="createOrderTable" width="100%"&gt;                   
    &lt;tr&gt;
      &lt;th&gt;Count&lt;/th&gt;&lt;th&gt;Product&lt;/th&gt;&lt;th&gt;Mesh&lt;/th&gt;&lt;th&gt;Delete&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;&lt;td&gt;OL&lt;/td&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;&lt;button type="button" class="close" aria-hidden="true" onclick="deleteRow('createOrderTable', 1)"&gt;&amp;times;&lt;/button&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>if I change </p>
  
  <p><code>btn.onclick = deleteRow('createOrderTable', rowCount );</code> </p>
  
  <p>to </p>
  
  <p><code>btn.onclick = deleteRow('createOrderTable', rowCount + 1 );</code> </p>
  
  <p>I can get the row to show but it throws </p>
  
  <p><code>Uncaught IndexSizeError: Failed to execute 'deleteRow' on 'HTMLTableElement': The index provided (3) is greater than the number of rows in the table (3).</code> </p>
  
  <p>and doesn't show the button. I'm confused about what I'm doing wrong here. </p>