Js operation node, ID, name, calssname, tag, style

Source: Internet
Author: User
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
02
Document. getElementById (id );
03
Returns access to the first object with the specified id.
04
 
05
Document. getElementsByName (name );
06
Returns a set of nodes with the specified name.
07
Note: Elements
08
 
09
Document. getElementsByTagName (tagname );
10
Returns an object set with the specified tag name.
11
Note: Elements
12
 
13
Document. getElementsByClassName (classname );
14
Returns an object set with the specified class name.
15
Note: Elements
16
 
17
2. Generate nodes
18
Document. createElement (eName );
19
Create a node
20
 
21
Document. createAttribute (attrName );
22
Create attributes for a node
23
 
24
Document. createTextNode (text );
25
Create a text node
26
 
27
3. Add nodes
28
Document. insertBefore (newNode, referenceChild );
29
Insert a node before a node
30
 
31
ParentNode. appendChild (newNode );
32
Add a subnode to a node
33
 
34
4. Copy a node
35
CloneNode (true | false );
36
Copy a node
37
Parameter: whether to copy all attributes of the original Node
38
 
39
5. delete a node
40
ParentNode. removeChild (node)
41
Delete a subnode of a node
42
Node is the node to be deleted.
43
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.
44
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.
45
 
46
6. modify a text node
47
AppendData (data );
48
Add data to the end of a text node
49
 
50
DeleteData (start, length );
51
Length characters will be deleted from start
52
 
53
InsertData (start, data)
54
Insert a character at start. The start value of start is 0;
55
 
56
ReplaceData (start, length, data)
57
Replace length with data at start
58
 
59
SplitData (offset)
60
Split text nodes at offset
61
 
62
SubstringData (start, length)
63
Extract length characters from start
64
 
65
7. Attribute operations
66
GetAttribute (name)
67
Obtains the value of a node attribute by using the attribute name.
68
 
69
SetAttribute (name, value );
70
Modifies the attribute value of a node.
71
 
72
RemoveAttribute (name)
73
Delete an attribute
74
 
75
8. Search for nodes
76
ParentObj. firstChild
77
This method can be used if the node is the first subnode of a known node. This method can be recursively used.
78
ParentObj. firstChild. firstChild .....
79
 
80
ParentObj. lastChild
81
Obtain the last node of a node, which can be recursively used like firstChild.
82
ParentObj. lastChild. lastChild .....
83
 
84
ParentObj. childNodes
85
Obtain all the subnodes of the node, and then find the target node through loops and indexes.
86
 
87
9. Obtain adjacent nodes
88
NeborNode. previussibling: gets the adjacent last node of a known node.
89
NerbourNode. nextSlbling: gets the next node of a known node.
90
 
91
10. Obtain the parent node
92
ChildNode. parentNode: Obtain the parent node of a known node.
 
From OO & XX
 

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.