

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add rows to a table using JavaScript DOM?
To add rows to a table with JavaScript, use the DOM method insertRow().
Example
You can try to run the following code to learn how to add a row to a table one at a time −
<!DOCTYPE html> <html> <head> <script> function rowFunction(x) { var a = document.getElementById(x).insertRow(0); var b = a.insertCell(0); var c = a.insertCell(1); b.innerHTML = c.innerHTML = "row"; } </script> </head> <body> <table style="border:2px solid black" id="newtable"> <tr> <td>One</td> <td>Two</td> </tr> <tr> <td>Three</td> <td>Four</td> </tr> <tr> <td>Five</td> <td>Six</td> </tr> </table> <p> <input type="button" onclick="rowFunction('newtable')" value="Add a row"> </p> </body> </html>
- Related Questions & Answers
- With JavaScript DOM delete rows in a table?
- Add elements to a hash table using Javascript
- How to add some rows to a table through DefaultTableModel in Java
- How to add table rows Dynamically in Android Layout?
- HTML DOM Table rows Collection
- How to add a class to DOM element in JavaScript?
- How to create a table caption with JavaScript DOM?
- How to add a new element to HTML DOM in JavaScript?
- How add unique key to existing table (with non-unique rows)?
- How to add a new row in a table using jQuery?
- How to use JavaScript DOM to change the padding of a table?
- How to layout table cells, rows, and columns with JavaScript?
- Add elements to a Queue using Javascript
- Add elements to a PriorityQueue using Javascript
- Add elements to a Set using Javascript
Advertisements