2014 Sinsing decoding JavaScript using the DOM to manipulate HTML elements dynamically?

Source: Internet
Author: User

With regard to DOM, we understand some of the properties and styles that can manipulate HTML with DOM, as well as the ability to bind events to HTML elements, and so on, then we will involve the use of DOM to dynamically create, delete HTML and other operations, my core thinking is still heavy combat, so, The Code demo sample is definitely not the case.

Just before using the DOM to manipulate HTML elements dynamically, let's look at the DOM tree first, and here's a picture of a DOM tree I'm looking for from the internet, like this:


Suppose you learn the "tree" data structure, it will be very good to understand that a parent node can include n child nodes, which may be Div, p and other tags, can be attributes, but also can be intermediate text information, for example, the above EM sub-node take your Time is a typical text node.

Suppose we need to add a new element to the DOM of the HTML, then we must first create the element and then add it to an existing element, which sounds like a mouthful. In fact, it is very well understood that we are able to introduce new content to the DOM tree by adding it, and JavaScript gives us a way to create that element and look directly at the following code, for example:


Then we find the effects such as the following:


To join the text node we use Addchild, then delete the child nodes, we can use RemoveChild, the other way of using the same as before.

Detailed function Everyone check the manual, I will not say, just feel this is not very useful ....

2014 Sinsing decoding JavaScript using the DOM to manipulate HTML elements dynamically?

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: info-contact@alibabacloud.com 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.