The document's advanced article provides functions for node operations, including: getting nodes, changing nodes, deleting nodes, replacing nodes, creating nodes, adding nodes, cloning nodes, and so on. We can use these functions to dynamically change the nodes of the HTML.
1. JavaScript
<script type= "Text/javascript" > Function test1 () {//The case of a node ID at the same time var myhref = document.getElementById (' same ');
Window.alert (Myhref.innertext); The value of the function test2 () {//Output node is var hobbies = document.getelementsbyname ("hobby"); for (var i = 0; i < hobbies.length; i+
+) {if (hobbies[i].checked) {window.alert ("Your hobby is:" + Hobbies[i].value);}} function Getn () {//tags to get label corresponding value var myobj = document.getelementsbytagname (' input '); for (var i = 0; i < myobj.length i
+ +) {Window.alert (Myobj[i].value);}} function Addtags () {////Dynamically add Hyperlink node <a></a>//(1) Create element <a> var myelement = document.createelement ("a")//(2
Add the necessary marking information to the element myelement.href = "http://www.sina.com";
Myelement.innertext = "Connect to Sina";
MyElement.style.left = "200px";
MyElement.style.top = "300px";
MyElement.style.position = "absolute";
Add to Document.body document.body.appendChild (myelement);
} var i = 1; function Addinput () {//Add INPUT element var myelement = document.createelement (' input '); myelement.type = "button";
Myelement.value = "Run It";
Myelement.id= "i++";
Myelement.id = "ID1";
document.getElementById ("Div1"). AppendChild (myelement); The function Deleteinput () {//Deletes an element only if you want to know what its parent element is.
This method is not very flexible//method one//document.getelementbyid ("Div1"). RemoveChild (document.getElementById (' id1 '));
Method two document.getElementById (' Id1 '). Parentnode.removechild (document. getElementById (' id1 ')); } </script>
calls in the 2.body body
<body> <a id= "Same" href= "http://www.sohu.com" > Sohu </a> <a id= "Same" href= "http://www.baidu.com" > Baidu </a> <a id= "Same" href= "http://www.sina.com" > Sina </a> <input type= "button" value= "Submit" Onclick= "test1 ()"/> <!--ID is the same when only know the first-->