1

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!

View Image Here

0

2 Answers 2

1

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 .

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you so much! But, your link haven't solved my problem yet. :( :( 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 believe you'll just need to do the same thing again.
0

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>

2 Comments

Thanks you so much! Your link haven't solved my problem yet. 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.
@TrinhThienAn please, try the snippet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.