Copy code code as follows:
<html>
<script language = "javascript" type = "text/javascript">
function test () {
// Create elements
var myelement = document.createElement ("a"); // A is the label name of the HTML element you want to create
// Add the necessary information to the created element
myelement.href = "http://www.baidu.com";
myelement.innertext = "Connect to Baidu";
myElement.id = "ID1";
//myElement.style.top = "300px";
//myElement.style.left = "500px";
//myElement. Style.position = "Absolute";
// Add the created elements to the body object
//document.body.appendchild (MyELEMENT);
// Add the element to the div
document.GetelementByid ("DIV1").
}
Function test2 () {) {
// Delete an element
// You can also obtain the parent element of the new element through the attribute
//document.GetelementByid.
document.GetelementByid ("DIV1"). Removechild (docume
}
</script>
<body>
<input type = "Button" onClight = "Test ()" Value = "Vitalizing a Hyperlink"/>
<input type = "Button" onClight = "Test2 ()" Value = "Dynamic Delete the added element"/>
<div ID = "div1" style = "width: 200px; height: 300px; border: 1px solid red">
div1
</div>
</body>
</html>