Deleting Layers
Question: How do I delete a layer from JavaScript?
Answer:
Here's the example that you've already seen in the
Creating Layers
section:
This example was created using the following code:
<form>
<input type=button value="Create layer"
onClick="makeLayer('LYR1',200,10,100,100,'red',1,1)">
<input type=button value="Delete layer"
onClick="deleteLayer('LYR1')">
</form>
To delete a layer, given the layer's ID, this code calls the function
deleteLayer(id)
.
Here's the JavaScript source code of this function:
function deleteLayer(id) {
if (document.layers && document.layers[id]) {
document.layers[id].visibility='hide'
delete document.layers[id]
}
if (document.all && document.all[id]) {
document.all[id].innerHTML=''
document.all[id].outerHTML=''
}
}
JavaScripter.net.
Copyright
© 1999-2006, Alexei Kourbatov