IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes Regarding DOM methods Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Regarding DOM methods" Watch "Regarding DOM methods" New topic
Author

Regarding DOM methods

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 65
Hi Can anyone here please explain me what does the following code do with an example?

while(node.firstChild)
node.removeChild(node.firstChild)

assume node is sth like var node=document.getElementById(id);

I know that it removes all the child nodes of a node represented by id="id". I dont know how a while loop works here.

Thanks
Vivek
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003


It loops until there are no more children left.

Eric
 
 
subject: Regarding DOM methods
 
Threads others viewed
Ajax and Java Applet crashes FireFox 1.5
If last char of textarea is \n, Safari 3.2.1 seems to think the textarea contains extra \n.
Ajax to refresh list
appending node to xml file
Implement linked list in java
IntelliJ Java IDE