Node properties and operations summary under DOM

Source: Internet
Author: User
Tags tagname

Property:
1. NodeName
The node name, which is equivalent to tagname. Property node returns the property name, and the text node returns #text. NodeName, is read-only.
2. NodeType
Value: 1, Element node, 2, Attribute node, 3, text node. NodeType is read-only.
3. NodeValue
Returns a string that indicates the value of this node. The element node returns NULL, the property node returns the property value, and the text node returns text. NodeValue can be read and writable, which is not writable on element nodes. Typically used only to set the value of a text node.
4. ChildNodes
Returns an array of child nodes. The childnodes of text and attribute nodes is always null. You can use HasChildNodes () to determine if there are child nodes. Read-only properties, to remove add nodes can not be manipulated using the ChildNodes array method, uh.
5. FirstChild
Returns the first child node. Text and attribute nodes do not have child nodes, and an empty array is returned, which is a special treatment for these two bits. For element nodes, NULL is returned if there are no child nodes. There is an equivalent: Firstchild=childnodes[0].
6. LastChild
Returns the last child node. return value with FirstChild, three-party treatment reference above. There is an equivalence formula: Lastchide=childnodes[childnodes.length-1].
7. nextSibling ()
Returns the next sibling node of the node. Returns null if there is no next sibling node. Read-only property, you cannot change the app.
8. PreviousSibling ()
Returns the previous sibling node of the node. Ditto.
9. parentnode ()
Returns the parent node of the node. Document.parentnode () returns null, and in other cases an element node is returned because only the element node has child nodes, and any node outside the document has a parent node. ParentNode (), again a read-only guy.


Operation:
1. Create a Node
createelement (' TagName ');
such as: Var op=document.createelement (' P '); Create a <p></p> tag.
2. Create a text node
createTextNode (' text ');
such as: Var Otext=document.createtextnode (' This is a paragh! ');
3. Attaching child nodes
AppendChild (o); where O is the node object.
such as: Document.body.appendChildNode (o); Append to Body end
Document.forms[0].appendchildnode (o); append at the end of form form
Op.appendchildnode (o); appended at the end of the element, whose total OP is the node object.
4. Create a document fragment
Createdocumentfragment ();
such as: Var of=document.createdocumentfragment ();
5. Delete a node
RemoveChild (OP);
such as: Document.body.removeChild (OP), removes the OP node object from the body.
6. Replacing nodes
Replacechid (newop,targetop); Replace the target node targetop with the Newop
such as: Document.body.replayChild (OPA,OPB). PS: How can this be so special? Both the source and the target operands are parameters, why is the caller document.body? Just remember, don't do more. --The replacement must be a child node of the body, which can be substituted with other element document.body, as the case may be, if the child node of this element is replaced.
7. Inserting nodes
Insertbefor (Newop,targetop);
InsertAfter (Newop,targetop);
8. Set or get the attribute node
SetAttribute (' key ', ' value ');
GetAttribute (' key ', ' value ')
9. Copy the node.
CloneNode (True/false)

Node properties and operations summary under DOM

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.