HTML DOM Node

Source: Internet
Author: User

All nodes

In the HTML DOM (Document Object model), nodes mainly include (numbers in parentheses denote node types): Elements (1), Attributes (2), text (3, where line breaks are also a text node), comments (8),文档(9)

The main application of these methods is to increase, delete, change and investigate.

1, increase, in the previous essay has introduced the two methods in detail.

2, delete, that is element.removechild () remove the child node from the element.

Syntax: Node.removechild (node)

Returns the node that was deleted as a node object, or null if it does not exist.

Step: (1) Get parent node (2) Get the node you want to delete (3) Delete node

Parent.removechild (child);

3, change, that is, Element.replacechild () Replace the child nodes in the element.

  语法:node.replaceChild(newnode,oldnode)

  新节点可以是文档中某个已存在的节点,或者您也可创建新的节点。

  旧节点会被删除

  步骤:(1)创建一个新节点或选择已有节点(2)获取父节点(3)获取想要被替换的节点 (4)替换节点

       parent.replaceChild(para,child);

4, check, query node, there are many methods, such as:

Element.firstchild returns the first child of the element.

Element.firstchild returns the first child of the element.

Element.nextsibling returns the next node at the same node tree level.

Element.nextsibling returns the next node at the same node tree level.

Element.parentnode returns the parent node of the element.

Element.parentnode returns the parent node of the element.

Element.parentnode returns the parent node of the element.

HTML DOM Node

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.