Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleteing Table Rows

Status
Not open for further replies.

SDyke

MIS
Oct 13, 2005
55
US
I have a static table with one row that contains header labels. I have javascript that dynamically added rows and populates the cells. Now I need a way to delete out the dynamically created rows so the next populate will start with only the one statis row.

How do I Know how many rows to delete and how do I delete from bottom up?
 
This sort of thing is best done by using <span> and/or <div> tags. You will need to give each tag a unique ID so that you can then change their attribute (display: none;) using getElmentByID('the_unique_id').style.display=none;

In the same token, you could simply put the entire thing within a <div> tag and add elements to your table as you are. Once you are done and want to revert back to one row, you can then use something like:

Code:
<script>
function RestLayer() {
  var content = '<table ...><tr><td>....</td></tr></table>';
  getElementByID('your_layers_ID').innerHTML=content;

}
</script>

You can se the variable 'content' to any HTML code set and then place it in the container. This is a very simple approach to what you are asking.

Hope this helps!


Out on the beach!
 
I assume your table is set up as per something like this:
Code:
<table>
 <thead>
  <tr><th>Heading 1</th><th>Heading 2</th></tr>
 </thead>
 <tbody id="mytbodyid"></tbody>
</table>

If so then:
Code:
document.getElementById("mytbodyid").innerHTML = "";
should do the trick

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top