Insert, Delete Rows, columns in HTML table Using Javascript
How to insert delete rows and cells dynamically in table using JavaScript Lets create a table object var table=document.CreateElement('table'); Or if you want to modify existing table then use below line. var table=document.getElementById('empTable'); you can set the attributes of table object using following code //Syntax object.setAttribute(attributeName, attributeValue); table.setAttribute("cellpadding","0"); table.setAttribute("cellspacing","0"); Now i want to add new row at the end, table, For this you need to get the Count of rows in table and Add the row at last index. var rows=table.getElementsByTagName('tr'); this will return the rows as array of object. Now insert new row at last index of table var lastIndex=rows.length; var newRow=table.insertRow(lastIndex); Now add the column to the newRow object. var cell=newRow.incertCell(0); Lets say i want to set inner HTML of this cell ...