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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

createElement & removeChild in IE problems...

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
0
0
AU
i wrote this script to test out the createElement and removeChild functions, it works fine in Mozilla, but in IE, it creates the DIV layer, but when i hit a key to activate the removeChild function it says that the DIV layer does not exist?

Code:
<html>
<head>
</head>
<script language=&quot;JavaScript&quot;>
	flag=false;
	document.onkeydown=test;
	
	function test() {
		if(flag==false) {
			layer=document.createElement(&quot;DIV&quot;);
			layer.setAttribute(&quot;ID&quot;,&quot;testlayer&quot;);
			layer.style.position=&quot;absolute&quot;;
			layer.style.border=&quot;1px solid black&quot;;
			layer.style.left=100;
			layer.style.top=100;
			layer.innerHTML=&quot;sdfsdf&quot;;
			document.body.appendChild(layer);
			flag=true;
		} else {
			layer=document.getElementById(&quot;testlayer&quot;);
			layer.parentNode.removeChild(layer);
			flag=false;
		}
		return false;
	}
</script>
<body>
</body>
</html>

please help
thanks

 
sorry the body tag should be:

<body onload=&quot;test()&quot;>

also i dont want the DIV tag to be hard coded within the body of the HTML, i want it to be pure javascript driven..

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top