blob84 Posted December 17, 2009 Share Posted December 17, 2009 Hi I need to delete every images in any cell, but this doesn't work.The function removes only the first image, the rows[1], cells[6]. function clearAll() { var table = document.getElementById("table"); for(c=6; c >= 0; c--) { //cells for(r=1; r <= 6; r++) { //rows table.rows[r].cells[c].removeChild.(createCircle); } } } Link to comment Share on other sites More sharing options...
Greywacke Posted December 17, 2009 Share Posted December 17, 2009 rather parse the rows before the cells as a row would be the parent of a cell.rows have cells as children, and cells have rows as parents.for example try something like this: function clearAll() { var table = document.getElementById("table"); for r = 0; r < table.rows.count; r++) { for (c=0; c < table.rows[2].cells.length; c++) { table.rows[r].cells[c].removeChild(dynamicImageReference); } }} Link to comment Share on other sites More sharing options...
Ingolme Posted December 17, 2009 Share Posted December 17, 2009 You have a '.' between the function and the parameters so it's not going to work: removeChild.(createCircle); Besides that, "createCircle" is a reference to one single element, so it's only going to be in one of the cells. One same element can't be in more than one place at a time. I don't see where createCircle is defined either so I don't even know if it is an element. Link to comment Share on other sites More sharing options...
jeffman Posted December 17, 2009 Share Posted December 17, 2009 Assuming you really want to remove ALL the images in your table (not just some of them), this does the trick: function clearAll () { var el = document.getElementById("table"); var ims = el.getElementsByTagName("img"); while (ims[0]) { ims[0].parentNode.removeChild(ims[0]); }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.