...

View Full Version : help removing div layer from screen



homerUK
06-09-2004, 11:43 AM
I add a DIV layer to my page using the appendChild() function.. here's the code:



div = document.createElement("DIV");
div.id = "layer1";
div.style.height = "200px";
div.style.width = "140px";
div.style.background = "#CCCCCC";
div.style.display = "block";
document.appendChild(div);


how do I then remove it from the screen?! I've tried

document.getElementById("layer1").style.display = "none";

but that has no effect. I was thinking something like removeChild() ?? But cant seem to find any documentation or tutorials on this sort of thing.

any help is much appreciated.

glenngv
06-09-2004, 11:57 AM
Have you confirmed that the div is really added?

You need to add it to the body or to any child element of it.

document.body.appendChild(div);

You can use any of the two methods to hide the div but if you want to show it later, it's easier to use

document.getElementById("layer1").style.display = "none";

and then setting it to 'block' later to display it.

homerUK
06-09-2004, 12:00 PM
yeah, I do a check:

if(document.getElementById("layer1"))
{
//remove it
}

so the code checks - and if there is the DIV layer, it removes it. Ive checked the code, it does show the div layer and adds the HTML code to the body. I wondered if there was a way of simply removing the element with the id "layer1" from the HTML code?

Ive tried to "hide" the div layer, and it didnt work....

jbot
06-09-2004, 12:14 PM
I was thinking something like removeChild() ?? But cant seem to find any documentation or tutorials on this sort of thing.


MSDN (http://msdn.microsoft.com/dhtml)

glenngv
06-10-2004, 04:31 AM
yeah, I do a check:

if(document.getElementById("layer1"))
{
//remove it
}

so the code checks - and if there is the DIV layer, it removes it. Ive checked the code, it does show the div layer and adds the HTML code to the body. I wondered if there was a way of simply removing the element with the id "layer1" from the HTML code?

Ive tried to "hide" the div layer, and it didnt work....
What does this say?

alert(document.getElementById("layer1"))
if(document.getElementById("layer1")){
//...
}

Also check for any error in the Javascript Console (NS/Moz) or in the exclamation icon (IE) in the status bar.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum