remove all rows from a table

Hi,

I got a HTML table script that lets you add and delete a row at a time. Is there a quick way to just delete ALL rows in the table at once? (I dont want to go call deleteRow() dozens of times to clear it if possible)

Thanks
LVL 7
minnirokAsked:
Who is Participating?
 
nabsolCommented:
Hi

Hope it helps.

<HTML><HEAD><TITLE>Test</TITLE>
<script language="JavaScript">
function deleteall(mytable)
{
   for(i=mytable.rows.length-1; i > -1; i--)
       mytable.deleteRow(i);
}
</script>

<BODY>

<table border="1" id="mytable">
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
</table>

<input type="button" onclick="deleteall(mytable)" value = "delete all">
</BODY></HTML>

By Nab
0
 
minnirokAuthor Commented:
Hi Nab,

That works, thanks - I have another question on list stuff which I'll post in a minute if you want to take a look,

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.