Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
011. access Node 02document. getElementById (id); 03 return to access 0405document for the first object with the specified id. getElementsByName (name); 06 returns the node set with the specified name 07 Note: Elements0809document. getElementsByTagName (ta 01
1. Access the node
Document. getElementById (id );
Returns access to the first object with the specified id.
Document. getElementsByName (name );
Returns a set of nodes with the specified name.
Document. getElementsByTagName (tagname );
Returns an object set with the specified tag name.
Document. getElementsByClassName (classname );
Returns an object set with the specified class name.
Document. createAttribute (attrName );
Create attributes for a node
Document. createTextNode (text );
Create a text node
3. Add nodes
Document. insertBefore (newNode, referenceChild );
Insert a node before a node
ParentNode. appendChild (newNode );
Add a subnode to a node
4. Copy a node
CloneNode (true | false );
Copy a node
Parameter: whether to copy all attributes of the original Node
5. delete a node
ParentNode. removeChild (node)
Delete a subnode of a node
Node is the node to be deleted.
Note: IE ignores the blank text nodes generated between nodes (for example, line breaks), but Mozilla does not. There will be no errors when deleting a specified node, but if you want to delete the last child node or the first child node, the problem will occur. At this time, a function is required to determine the node type of the first subnode.
The Node Type of the element node is 1. Therefore, if the first child node is not an element node, it will be moved to the next node and check whether the node is an element node. The entire process continues until the first element subnode is found. With this method, we can get the correct method in Internet Explorer and Mozilla.
6. modify a text node
AppendData (data );
Add data to the end of a text node
DeleteData (start, length );
Length characters will be deleted from start
InsertData (start, data)
Insert a character at start. The start value of start is 0;
ReplaceData (start, length, data)
Replace length with data at start
Split text nodes at offset
7. Attribute operations
Obtains the value of a node attribute by using the attribute name.
SetAttribute (name, value );
Modifies the attribute value of a node.
Delete an attribute
8. Search for nodes
This method can be used if the node is the first subnode of a known node. This method can be recursively used.
ParentObj. firstChild. firstChild .....
Obtain the last node of a node, which can be recursively used like firstChild.
ParentObj. lastChild. lastChild .....
Obtain all the subnodes of the node, and then find the target node through loops and indexes.
9. Obtain adjacent nodes
NeborNode. previussibling: gets the adjacent last node of a known node.
NerbourNode. nextSlbling: gets the next node of a known node.
10. Obtain the parent node
ChildNode. parentNode: Obtain the parent node of a known node.
From OO & XX
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.