Node attributes and Operation summary under DOM

Source: Internet
Author: User

Attribute:
1. nodeName
The node name, which is equivalent to tagName. The attribute node returns the attribute name, and the text node returns the # text. NodeName, which is read-only.
2. nodeType
Value: 1, Element Node; 2, attribute node; 3, text node. NodeType is read-only.
3. nodeValue
Returns a string indicating the value of this node. Element nodes return null, attribute nodes return attribute values, and text nodes return text. NodeValue can be read and written, which is not writable to element nodes. Generally, this parameter is only used to set the value of a text node.
4. childNodes
Returns an array of child nodes. The childNodes of the text and attribute nodes is always null. You can use hasChildNodes () to determine whether a subnode exists. Read-only attribute. to delete a node, you can use the childNodes array operation method.
5. firstChild
Returns the first subnode. If the text and attribute nodes do not have subnodes, an empty array is returned, which is a special treatment for these two nodes. If no child node exists for element nodes, null is returned. There is an equivalent formula: firstChild = childNodes [0].
6. lastChild
Returns the last subnode. The returned value is the same as firstChild. For details about the three-party treatment, refer to the above. There is an equivalent formula: lastChide = childNodes [childNodes. length-1].
7. nextSibling ()
Returns the next sibling node of the node. If no sibling node exists, null is returned. Read-only attribute. applications cannot be changed.
8. previussibling ()
Returns the last sibling node of the node. Same as above.
9. parentNode ()
Returns the parent node of the node. Document. parentNode () returns null. In other cases, an element node is returned, because only the element node has a subnode and any node outside the document has a parent node. ParentNode () is a read-only guy.


Operation:
1. Create a node
CreateElement ('tagname ');
For example, var oP = document. createElement ('P'); creates a <p> </p> label.
2. Create a text node
CreateTextNode ('text ');
For example, var oText = document. createTextNode ('this is a paragh! ');
3. Add a subnode
AppendChild (o); where o is a Node object.
For example: document. body. appendChildNode (o); append at the end of the body
Document. forms [0]. appendChildNode (o); append at the end of the form
OP. appendChildNode (o); append at the end of the element. The total oP is the Node object.
4. Create a document clip
CreateDocumentFragment ();
For example, var oF = document. createDocumentFragment ();
5. delete a node
RemoveChild (oP );
For example, document. body. removeChild (oP) removes the oP Node object from the body.
6. Replace nodes
ReplaceChid (newOp, targetOp); replace targetOp with newOp.
For example, document. body. replayChild (oPa, oPb). ps: how can this be special? Both the Source and Destination operands are parameters. Why is the caller document. body? Remember, don't worry. -- The child node to be replaced must be the body, and other elements can be used to replace document. body. The premise is the same. The child node to be replaced is the child node of this element.
7. Insert nodes
InsertBefor (newOp, targetOp );
InsertAfter (newOp, targetOp );
8. set or obtain attribute nodes
SetAttribute ('key', 'value ');
GetAttribute ('key', 'value ')
9. Copy the node.
CloneNode (true/false)

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.