<html>
<title>Adding and Removing nodes</title>
<script language="JavaScript">
function AddNode(tag){
if(!document.getElementById)
return;
element= document.createElement(tag);
if(tag!='HR'){
txt= document.form1.newtext.value;
element.innerHTML = txt;
}
s= document.getElementById("adhere");
s.appendChild(element);
}
function DeleteNode(){
if(!document.getElementById)
return;
s= document.getElementById("adhere");
s.removeChild(s.lastChild);
}
</script>
</head>
<body>
<h1>Adding and Removing Nodes</h1>
<p>Enter some text and use the buttons below to add or remove nodes from this page's DOM hierarchy</p>
<span ID ="adhere"></span>
<form name="form1" ID="form1">
<input type="text" name="newtext" size="70"><br>
<input type="button" value="Add Paragraph" onClick="AddNode('P');">
<input type="button" value="Add Heading" onClick="AddNode('H3');">
<input type="button" value="Add Line" onClick="AddNode('HR');">
<input type="button" value="Deleteanode" onClick="DeleteNode();">
</form>
</body>
</html>
OUTPUT
No comments:
Post a Comment