Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete the row you click on (Javascript dynamic table)
    text
    copied!<p>I want to delete a row from a table, I am using Javascript. I am dynamically creating table rows and in the last cell I have delete button so how to make it delete the row? </p> <pre><code>var newData4 = document.createElement('td'); var delButton = document.createElement('input'); delButton.setAttribute('type', 'button'); delButton.setAttribute('name', 'deleteButton'); delButton.setAttribute('value', 'Delete'); newData4.appendChild(delButton); newRow.appendChild(newData4); </code></pre> <p>this is the function for creating my table rows </p> <pre><code> function addItem() { document.getElementById('add').onclick=function() { var myTable = document.getElementById('tbody'); var newRow = document.createElement('tr'); //var element1 = document.createElement("input"); //element1.type = "checkbox"; //newRow.appendChild(element1); var newData1 = document.createElement('td'); newData1.innerHTML = document.getElementById('desc').value; var newData2 = document.createElement('td'); newData2.innerHTML = document.getElementById('taskPriority').value; var newData3 = document.createElement('td'); newData3.innerHTML = document.getElementById('taskDue').value; myTable.appendChild(newRow); newRow.appendChild(newData1); newRow.appendChild(newData2); newRow.appendChild(newData3); var newData4 = document.createElement('td'); var delButton = document.createElement('input'); delButton.setAttribute('type', 'button'); delButton.setAttribute('name', 'deleteButton'); delButton.setAttribute('value', 'Delete'); newData4.appendChild(delButton); newRow.appendChild(newData4); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload