Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > javascript: clear all childNodes

javascript: clear all childNodes
Thread Tools
Junior Member
Join Date: Nov 2004
Location: Michigan
Status: Offline
Reply With Quote
Jun 28, 2005, 09:07 AM
 
I wrote the code below for clearing out a row in a table. The problem is this function is very sporadic on how it works and never does it quite right. Does anyone know a better way of doing this? I'm trying to avoid innerHTML since its not in the W3C DOM spec.

Code:
function clear(obj) { group = obj.childNodes; for (i = 0; i < group.length; i++) { obj.removeChild(group[i]); } }
edit: One more thing, one of the cells holds another table inside it and that's where I seem to run into problems.
(Last edited by ctlq; Jun 28, 2005 at 09:21 AM. )
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Jun 28, 2005, 10:17 AM
 
function annihilateChildren(obj) {
while(obj.firstChild) {
obj.removeChild(obj.firstChild);
}
}

I don't know if that's the best way to do it or not, but that's a bit of script I recently used in a widget so it works in Safari.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:18 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2