Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with DOM childNodes

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
hi all,

any dom experts out there. i'm trying to use removeChild, appendChild and insertBefore to implement a cut-n-paste routine. everything works great in ie, but ns6 is not cooperating. looking for some guidance.

specifically, i can't get the insertBefore method to work properly in ns6. my test page for this follows...

Code:
<html><head><title>DOM Test</title>
<style type=&quot;text/css&quot;>
<!--
.clsBox {
 width: 50;
 height: 50;
 margin-bottom: 10;
}
.clsClipBoard {
 position: absolute;
 right: 10;
 top: 10;
 border-width: 2;
 border-style: solid;
 width: 60;
 height: 60;
}
.clsColumn {
 position: absolute;
 top: 100;
}
-->
</style>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
function change(obj) {
 var clipBoard = document.getElementById(&quot;clipBoard&quot;);
 var delNode;
 if (!clipBoard.hasChildNodes()) {
  if (confirm(&quot;Cut Section?&quot;)==true)	{
	  var delNode = obj.parentNode.removeChild(obj);
	  clipBoard.appendChild(delNode);
	}
 }
 else {
  if (confirm(&quot;Paste From ClipBoard&quot;)==true)	{
	 if (obj.nextSibling == null || (obj.nextSibling.nodeType==3 && obj.nextSibling.nextSibling==null))	 {
	  if (confirm(&quot;Click 'Yes' to paste above.  Click 'Cancel' to paste below.&quot;)==false)	{
		  obj.parentNode.appendChild(clipBoard.firstChild); //this works fine in ns6
		}
		else	{
		  obj.parentNode.insertBefore(clipBoard.firstChild,obj); //this doesn't work in ns6
		}
	 }
	 else	 {
	  obj.parentNode.insertBefore(clipBoard.firstChild,obj); //this doesn't work in ns6
   }
	}
 }
}
//-->
</script></head><body>
<div id=&quot;column1&quot; class=&quot;clsColumn&quot; style=&quot;left: 100&quot;>
<div id=&quot;box1&quot; class=&quot;clsBox&quot; style=&quot;background-color:orange&quot; onclick=&quot;change(this)&quot;></div>
<div id=&quot;box2&quot; class=&quot;clsBox&quot; style=&quot;background-color:pink&quot; onclick=&quot;change(this)&quot;></div>
<div id=&quot;box3&quot; class=&quot;clsBox&quot; style=&quot;background-color:green&quot; onclick=&quot;change(this)&quot;></div>
</div>
<div id=&quot;column2&quot; class=&quot;clsColumn&quot; style=&quot;left: 200&quot;>
<div id=&quot;box4&quot; class=&quot;clsBox&quot; style=&quot;background-color:purple&quot; onclick=&quot;change(this)&quot;><span>Text</span></div>
<div id=&quot;box5&quot; class=&quot;clsBox&quot; style=&quot;background-color:yellow&quot; onclick=&quot;change(this)&quot;><span>Text</span></div>
<div id=&quot;box6&quot; class=&quot;clsBox&quot; style=&quot;background-color:red&quot; onclick=&quot;change(this)&quot;><span>Text</span></div>
</div>
<div id=&quot;clipBoard&quot; class=&quot;clsClipBoard&quot;></div></body></html>

any ideas???

also, it appears that ns6 creates a text type child node for each tag, so that even if a tag doesn't have a specified child tag, ns6 will report a child node of type text. ie, on the other hand, only reports a child node where you have specifically created one. any ideas on why this is? any comments on the implications of this when working with nodes in ns6?

thanks,

glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top