[Javascript] Need to loop through all element in a div cross browser

Hakan M (Backbase) hakan at backbase.com
Thu Dec 9 10:35:05 CST 2004


Something like this:


var oDiv = document.getElementById('parentDiv');
if(oDiv.firstChild) { // check for children
   var oChild = oDiv.firstChild;
   while(oChild) { // run over them
     if(oChild.nodeType==1) { // element
       // oChild is a first level child of oDiv
       // Do what you want with it here
     }
     oChild = oChild.nextSibling;
   }
}


Didn't try it, but you get the point.

Regards,
H


Laurent Muchacho wrote:
> Hi All,
> 
> Guy's I seriously need your help.
> What I'm trying to do is a loop through all element first level nested
> contained in a DIV.
> The Idea is to reproduce the document.all implemented by IE but cross
> browser.
> Please if you think it's impossible please reply and let me know.
> 
> Found below an examples of my html
> 
> <div id="parentDiv">
> 	<input type="text" name="test1" value="">
> 	<input type="text" name="test2" value="">
> 	<input type="text" name="test3" value="">
> 	<input type="text" name="test4" value="">
> 	<input type="text" name="test5" value="">
> 	<select name="select1">
> 		<option>test 1</option>
> 		<option>test 1</option>
> 		<option>test 1</option>
> 		<option>test 1</option>
> 	</select>
> 	<div id="childDiv1">
> 		don't want to count the item nested in this element
> 		<input type="text" name="childDiv1test1" value="">
> 	</div>
> 	<div id="childDiv2">
> 		don't want to count the item nested in this element
> 		<input type="text" name="childDiv2test1" value="">
> 	</div>
> </div>
> 
> Thanks in advance.
> 
> Laurent
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> 

-- 
Hakan Magnusson
Senior Software Engineer
E. hakan at backbase.com
M. +31 (0)6 430 40 112

BACKBASE BV
Stephensonstraat 19
1097 BA  Amsterdam

W. http://www.backbase.com/
T. +31 (0)20 750 7305
F. +31 (0)20 750 7301

# Winner of the Broos van Erp Prize (Best High Tech Starter 2004)
# Winner of Golden SPIN Award (Innovation Prize 2003)



More information about the Javascript mailing list