How to dynamically add tags in javascript document, including javascriptdocument

Source: Internet
Author: User

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 = ""> Sohu </a> <a id = "same" href = ""> Baidu </a> <a id = "same" href = ""> 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 ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.