HTML and CSS Reference
In-Depth Information
Figure 15.27 A div container is removed.
EXAMPLE 15.16
<html>
<head><title>Delete an Element with the DO</title>
<style type="text/css">
p { font-style:arial;
color:darkblue;
font-size:18
}
</style>
<script type="text/javascript">
1
function remove(f){
2
for(var i=0; i<f.choice.length; i++){
3
if( f.choice[i].checked ){
// Find the paragraph that was checked
4
var p_element=document.getElementById(f.choice[i].value);
5
document.body.removeChild(p_element)
}
}
}
</script>
</head>
<body>
<script type="text/javascript">
// Create three paragraphs with text
6
for(var i=1; i <= 3; i++){
var aPara=document.createElement("p");
var aBR = document.createElement("br");
var aTXT1=document.createTextNode("Hello, world. ");
var aTXT2=document.createTextNode("I really don't
want to be deleted! ");
var aTXT3=document.createTextNode("I am paragraph " + i);
7
aPara.setAttribute("id","aPara" + i);
document.body.appendChild(aPara);
aPara.appendChild(aTXT1); //Put paragraph in the doc
aPara.appendChild(aBR);
Continues
Search WWH ::




Custom Search