473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to empty a node

Hi,

I have a TBODY node with id="thebody". How do I use JS to empty all
its contents so that the DOM after the call would look like

<tbody id="thebody"></tbody>

? Thanks, - Dave
Sep 19 '08 #1
4 5373
laredotornado wrote:
I have a TBODY node with id="thebody". How do I use JS to empty all
its contents so that the DOM after the call would look like

<tbody id="thebody"></tbody>

var el = document.getElementById('thebody');
while (el.hasChildNodes())
{
el.removeChild(el.lastChild);
}

or
el.innerHTML = '';
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 19 '08 #2
On Sep 19, 5:18*pm, Martin Honnen <mahotr...@yahoo.dewrote:
* *var el = document.getElementById('thebody');
* *while (el.hasChildNodes())
* *{
* * *el.removeChild(el.lastChild);
* *}
or

var a, e= document.getElementById('thebody');
while (a= e.firstChild) {
e.removeChild(a);
}
or
* *el.innerHTML = '';
Sep 19 '08 #3
SAM
Jorge a écrit :
On Sep 19, 5:18 pm, Martin Honnen <mahotr...@yahoo.dewrote:
> var el = document.getElementById('thebody');
while (el.hasChildNodes())
{
el.removeChild(el.lastChild);
}

or

var a, e= document.getElementById('thebody');
while (a= e.firstChild) {
e.removeChild(a);
}
>or
el.innerHTML = '';
or :

var rws = [];
function emptyTbody(){
var T = document.getElementById('thebody');
R = T.rows;
rws.length = 0;
while(R.length 0) rws.push(T.removeChild(R[0]));
}
function fillBackTbody(){
var T = document.getElementById('thebody');
R = T.rows
k = 0;
n = rws.length;
if(n 0) while(R.length < n) { T.appendChild(rws[k]); k++; }
}

--
sm
Sep 19 '08 #4
On Sep 20, 1:16*am, laredotornado <laredotorn...@zipmail.comwrote:
Hi,

I have a TBODY node with id="thebody". *How do I use JS to empty all
its contents so that the DOM after the call would look like

<tbody id="thebody"></tbody>

? *Thanks, - Dave
For a large number of rows, it may be faster to replace the tbody with
a shallow clone of itself:

var el = document.getElementById('theBody');
el.parentNode.replaceChild(el.cloneNode(false), el);
--
Rob
Sep 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mr_burns | last post by:
Hi, I am using the following function to access a nodes value from an XML file. It works fine until it discovers a empty tag. I would like to have the option of leaving some tags empty for my...
2
by: Victor | last post by:
While debugging my stylesheet using XMLSpy, I got a really weird result: <xsl:if test="$match = true()"> matches even if $match is an empty node fragment. How can this be? -- Victor
4
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work)...
4
by: Michael Frost | last post by:
Loading and saving a xml document in .net creates whitespace in empty nodes! loading an empty node like: <node></node> ..net saves as: <node> </node>
0
by: chris yoker via DotNetMonster.com | last post by:
hiya, I previously obtained code that enabled me the replace a node and its innerText.The code relied on the node that was to be replaced having ?childNodes? However, it seems that the nodes...
2
by: Todd Price | last post by:
I'm trying to use XPath to get a handle on one specific node so that I can replace it with an xml fragment I've loaded from another file. So if I have this XML: <issue> <id>1</id>...
2
by: Tjerk Wolterink | last post by:
I have a variable $value as a parameter in the following template: <xsl:template name="myTemplate"> <xsl:param name="value"/> <xsl:if test="$value"> <xsl:value-of select="$value"/> </xsl:if>...
2
by: junkblog747 | last post by:
What will the expression "/.." in the attribute select="/.." return? I just inherited a huge stylesheet to maintain which has a lot of parameters such as <xsl:param name="myParam"...
2
by: esebastian | last post by:
Hi all, Basically i want to do get the specific node that is empty but when i try the following i get a null node even though I know there is a node whose AN value is null. What am i doing wrong?...
4
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; If I have an XPathNavigator object and for a given xpath statement need to know if the node exists, how should I do this? I have found for some xpath functions it returns an empty string if...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.