[Javascript] re : recursively moving through DIVs

MikeMu at paccessglobal.com MikeMu at paccessglobal.com
Thu May 10 13:23:43 CDT 2001


Greetings,

	Browser problem : Netscape 4+ (only testing on 4.72 right now)
	Issue : Recursion through layers

	I am having a hard time getting a function to reliably recurse
through some DIVs (some nested) 

	I am pretty much at the point where I feel that the Netscape 4.72
doesnt really support this as 	an object as oppose to their <LAYER> tag
(grr) I can recurse through that fine. 
	But DIVs dont work. :(
	
	Is there a version of Netscape 4+ that this may actually work in ?
Cause I know that Netscape 4+ 	is pretty inconstistent about its DOM model
in these releases.

	I can traverse into the children but then the traversal stops after
one post order point 
	I am not succeeding with a full pre and post order traversal of the
tree.

	eg.
		layer1
			<recurse in>
			layer2
				<recurse in>
				layer3
			<recurse out>
			layer2 --STOP--
		//doesnt pop out to here ??
		<recurse out>
		layer1
	
	i am actually trying to emulate ie's flat access DOM in netscape by
storing all the nested layers
	in an array instead of using the
document.layers[i].document.layers[i].document.layers[i]....zzzz 	crap

--code--
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--

 document.menu = new Object();
 document.menu.parts = new Array();
 document.menu.names = new Array();
 document.menu.heights = new Array();

var i = 0;
var n = 0;

function buildLayerArray(layerobj){

	if(document.layers){
	
		for(i=0; i< layerobj.document.layers.length; i++){
		
	
document.menu.parts[layerobj.document.layers[i].name] =
layerobj.document.layers[i];
			alert("Pre Order" + " = "
+layerobj.document.layers[i].name );
			
			if ( layerobj.document.layers[i].layers.length > 0
){ //has kids so recurse in
				buildLayerArray( layerobj.document.layers[i]
);
			}
			alert("Post ORder"+ " = "
+layerobj.document.layers[i].name);
		}

	}
}
// -->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<a href="#" onclick="buildLayerArray(document.layers['lay']); return
false">click me</a>
<div id="lay" style="position:absolute ; width:200px; height:115px;
z-index:1; visibility:visible">lay
  <div id="dud" style="position:absolute ; width:200px; height:115px;
z-index:1; visibility:visible"> dud  </div>
  <div id="asdf" style=" position:absolute ; width:200px; height:115px;
z-index:1; visibility:visible"> asdf 
  			<div id="gnj" style="position:absolute ;
width:200px; height:115px; z-index:1; visibility:visible">gnj</div>
  </div>
  
<div id="ferwerd" style="position:absolute;  width:200px; height:115px;
z-index:1; visibility:visible">ferwerd 
</div>
</div>
</body>
</html>

code-

	




More information about the Javascript mailing list