<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function deleterow (r)
{
VaR I = R. parentnode. parentnode. rowindex
Document. getelementbyid ('mytable'). deleterow (I)
}
Function insertrowintable (){
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function deleterow (r)
{
VaR I = R. parentnode. parentnode. rowindex
Document. getelementbyid ('mytable'). deleterow (I)
}
Function insertrowintable (){
VaR table = Document. getelementbyid ("mytable ");
VaR newrow = table. insertrow (-1 );
Newrow. insertcell (). innerhtml = newrow. rowindex;
Newrow. insertcell (-1). innerhtml = "<input type = 'button 'value = 'delete 'onclick = 'deleterow (this)'> ";
}
</SCRIPT>
</Head>
<Body>
<Table id = "mytable" border = "1">
<Tr>
<TD> Row 1 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
<Tr>
<TD> Row 2 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
<Tr>
<TD> Row 3 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
</Table>
<Input type = "button" onclick = "insertrowintable ();" value = "insert a row"/>
</Body>
</Html>
Deleterow () deletes a row from the table.
Insertrow () inserts a new row into the table.
Innerhtml sets or returns the HTML between the start tag and end tag of the row.
Rowindex returns the position of the row in the table.
VaR table = Document. getelementbyid ("mytable ");
VaR newrow = table. insertrow (-1 );
Newrow. insertcell (). innerhtml = newrow. rowindex;
Newrow. insertcell (-1). innerhtml = "<input type = 'button 'value = 'delete 'onclick = 'deleterow (this)'> ";
}
</SCRIPT>
</Head>
<Body>
<Table id = "mytable" border = "1">
<Tr>
<TD> Row 1 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
<Tr>
<TD> Row 2 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
<Tr>
<TD> Row 3 </TD>
<TD> <input type = "button" value = "delete" onclick = "deleterow (this)"> </TD>
</Tr>
</Table>
<Input type = "button" onclick = "insertrowintable ();" value = "insert a row"/>
</Body>
</Html>