How to dynamically add tags in javascript document, including javascriptdocument
The advanced document provides functions for node operations, including obtaining nodes, changing nodes, deleting nodes, replacing nodes, creating nodes, adding nodes, and cloning nodes. We can use these functions to dynamically change html nodes.
1. JavaScript
<Script type = "text/javascript"> function test1 () {// var myhref = document when the ID of each node is the same. getElementById ('same'); window. alert (myhref. innerText);} function test2 () {// output node value var hobbies = document. getElementsByName ("holobby"); for (var I = 0; I
2. Call in the 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 () "/> <! -- When the ID is the same, only the first one is known -->
The above is all the content of the dynamic tag adding method in the javascript document that xiaobian brings to you. I hope you can support more help ~