removeChild()

Hi;
I have this code:


<html>
<head>
<style type='css/text'/>
splash { position:absolute; left:0px; top:0px; z-index:2 }
page { position:absolute; left:0px; top:0px; z-index:1 }
</style>
<script type='text/JavaScript1.2'>
function rem() {
	var t = document.getElementById(&#8217;splash&#8217;);
	t.parentNode.removeChild(t);
}
</script>
</head>
<body onload="setTimeout(rem(), 500)">
<div class='page'>
 <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
 WIDTH="250" HEIGHT="95" id="globaloilcounter_external1"> 
<PARAM NAME=movie VALUE="GlobalSolutions.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED href="GlobalSolutions.swf" quality=high bgcolor=#FFFFFF WIDTH="1008" HEIGHT="200" NAME="GlobalSolutions" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT> 
</div>
<div class='splash' id='splash'>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" 
WIDTH="250" HEIGHT="95" id="globaloilcounter_external1"> 
<PARAM NAME=movie VALUE="globalSolutionsSplash.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED href="globalSolutionsSplash.swf" quality=high bgcolor=#FFFFFF WIDTH="1008" HEIGHT="200" NAME="globalSolutionsSplash" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT> 
</div>
</body>
</html>

Why doesn’t this remove the ‘splash’ element in half a second?
TIA,
Victor

Hi Victor and welcome to SitePoint .
Check which quotes you have around the getElementById call
It might be the forum software but it looks like:


var t = document.getElementById(&#8217;splash&#8217;);

should be


var t = document.getElementById('splash');

If you are using firefox then download the Web Developers plugin as the javascriptp debugger is very useful.

SpikeZ just responded that I had used Mac single-quotes for a variable. That corrected, the script now indeed does remove the element…but immediately! Even if I change this line thus:

<body onload=“setTimeout(rem(), 500000)”>

the element ‘splash’ never shows up on stage! Why?
TIA,
Victor

Change:


<script type='text/JavaScript1.2'>

to


<script type='text/javascript'>

and


<body onload="setTimeout(rem(), 500000)"> 

to


<body onload="setTimeout('rem()', 500)"> 

It worked! Thanks!
V

np :slight_smile:

A better way would be to do this,

<body onload="setTimeout(rem, 500)">

By specifying a string value, as spikeZ suggested, the JavaScript parser will have to do an eval() (which is evil).
Using a function reference obviates the need for that.

The error in the original code was that you used a function call (rem()) instead of a function reference (rem) as the first argument to setTimeout().