DOM method and attribute Summary

Source: Internet
Author: User

1. Create a node:

Create a new element node: createelement () [Reference = Document. createelement (element )]

Create a new text node: createtextnode () [Reference = Document. createtextnode (text )]

2. Copy nodes:Clonenode () [Reference = node. clonenode (deep) // The parameter deep value of this method can only be true/false, indicating whether to copy the child nodes of the replication node to the new node together]

3. Insert nodes:

Append a subnode to a given element.

Appendchild () [Reference = element. appendchild (newchild) // newchild will be the last node of the element node]

Insert a given node to a given element node before the child node

Insertbefore () [Reference = element. insertbefore (newnode, targetnode )]

4. delete a node:Removechild () [Reference = element. removechild (node) // delete a subnode from a given element node]

5. Replace nodes:ReplaceChild () [Reference = element. replaceChild (newchild, oldchild) // replace one subnode in a given parent element with another node]

6. processing nodes:

7. Search nodes:

Getattribute () [attributevalue = element. getattribute (attributename) // returns the value of a given attribute node for a given element]

Getelementbyid () [element = Document. getelementbyid (ID) // find an element with a given ID attribute value]

Getelementsbytagname () [elements = Document. getelementsbytagname (tagname) // you can call this operation to find all the elements that have been signed for the calibration. A set is returned]

Haschildnodes [booleanvalue = element. haschildnodes // check whether a given element has subnodes. Neither the text node nor the attribute node can contain any subnodes]

8. node attributes:Each node in the document has the following attributes:

Nodename is a read-only attribute [name = node. nodename // The element name returned by the element node, the attribute node returns the attribute name, and the text node returns the string # text]

Nodetype indicates the type of the given node. [integer = node. nodetype // nodetype has 12 optional values]

Nodevalue indicates the current value of the given node [value = node. nodevalue // This attribute returns a string. The attribute node returns the value of this attribute. The text node returns the content of this text node, and the element node returns NULL]

9. traverse the node tree:

The childnodes attribute returns an array consisting of subnodes of a given element node: nodelist = node. childnodes, number of subnodes: node. childnodes. length, read-only attribute

The firstchild attribute returns the first child node of a given element node: reference = node. firstchild is equivalent to reference = node. childnodes [0], read-only attribute

The lastchild attribute returns the last child node of a given element node: reference = node. lastchild is equivalent to reference = node. childnodes [node. childnodes. Length-1], read-only.

Nextsibling attribute, returns the next node of a given node: reference = node. nextsibling, read-only attribute

Returns the parent node of a given node: reference = node. the node returned by the parentnode and parentnode attributes is always an element node, because only the element node can contain the child node except the document node.

Previussibling attribute, returns the previous subnode of a given node: reference = node. previoussibling, read-only attribute

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.