In line8:- it has element.parentElement.remove(element), here the element it refers to what tag in HTML?
Note:- This the fiddle code, in case you need it.
Javascript
var td4 = document.createElement('td');
td4.setAttribute("id", "td4");
td4.innerHTML = <button
onclick=remove(this.parentElement)>X</button> *line4
tr.appendChild(td4);
function remove(element){
element.parentElement.remove(element) **line8**
}
HTML
<div class='table'>
<table id="table">
<th>
<tr>
<td>Task</td>
<td>Date</td>
<td>Urgency</td>
<td>Done</td>
</tr>
</th>
<button onclick=clearAll()> Clear All </button>
</table>
</div>
You should use template strings .
// You'll need to access to the tr element. // Also, I would recommend use const instead of var const tr = document.querySelector('tr'); const td4 = document.createElement('td'); td4.setAttribute("id", "td4"); // You'll need to use the parentElement property twice, because the button will be inserted into the 'td' and you need access to the 'tr' td4.innerHTML = `<button onclick=remove(this.parentElement.parentElement)>X</button>` tr.appendChild(td4); function remove(element){ element.parentElement.remove(element) }
<div class='table'> <table id="table"> <th> <tr> <td>Task</td> <td>Date</td> <td>Urgency</td> <td>Done</td> </tr> </th> <button onclick=clearAll()> Clear All </button> </table> </div>
Read more about Accessing the DOM here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.