I have 2 add button. First add button on header, click this button will add 1 new row. Second add button in table (such as image on my post), click this button will add new row such as image my post. I want add row in table such as below image, but i haven't thought of a solution yet. Hope to be got your helps!
The insertRow()
method allows you to add rows to a <table>
and returns a reference to a new row. Adding that to an onClick()
function should be easy! :)
Here's the relevant information on Mozilla's site .
To solve this, you have to add a new table inside td, like this
function addNewRow() { let table = document.getElementById("add"); table.innerHTML += '<table><tr><td><b>This is a test</b></td></tr></table>'; }
<html> <body> <button onclick="addNewRow()">Add</button> <table id='my-table'> <tr> <td>This is one td</td> <td id='add'>This is another td</td> </tr> </table> </body> </html>
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.