1 createelement (element)
Create a specified tag name and create a new element node. The returned value is the reference pointer pointing to the new element node.
EG) var para = Document. createelement ("p ");
Document. Body. appendchild (para );
2 createtextnode ()
Create a new text node that contains the given text and return a reference pointer pointing to the new text node:
Reference = Document. createtextnode ()
The parameter is the text string contained in the new text node.
EG)
VaR message = Document. createtextnode ("Hello World ");
VaR Container = Document. createelement ("p ");
Container. appendchild (Message );
Document. Body. appendchild (container );
3 clonenode ()
Reference = node. clonenode (deep)
Create a copy for a given node. The parameter is true or false. True indicates that the child node of the node is copied at the same time. If false, no child node is copied.
VaR para = Document. createelement ("p ");
VaR message = Document. createtextnode ("Hello World ");
Para. appendchild (Message );
Document. Body. appendchild (para );
VaR newpara = para. clonenode (true );
Document. Body. appendchild (newpara );
4 appendchild ()
Reference = node. appendchild (newchild );
Insert a node. For example, refer to the previous section.
5 insertbefore ()
Reference = element. insertbefore (newnode, targetnode)
Insert a given node to the front of a given element node to the child node, and return a reference pointer pointing to the new child node.
EG)
VaR Container = Document. getelementbyid ("content ");
VaR message = Document. getelementbyid ("fineprint ");
VaR para = Document. createelement ("p ");
Container. insertbefore (para, message );
6 removechild ()
Reference = element. removechild (node)
Deletes a subnode from a given element and returns a reference pointer pointing to the deleted subnode.
When a node is deleted by removechild (), all its subnodes are deleted.
7 replaceChild ()
Reference = element. replaceChild (newchild, oldchild)
Replace a child node in a given parent element with another node. The oldchild node must be a child node of the element. The returned value is a pointer to the replaced one.
The reference pointer of the subnode.
EG)
VaR Container = Document. getelementbyid ("content ");
VaR message = Document. getelementbyid ("fineprint ");
VaR para = Document. createelement ("p ");
Container. replaceChild (para, message );
8 setattribute ()
Element. setattribute (attributename, attributevalue );
Add a new attribute value for a given element node or change its existing attribute.
9 getattribute
Attributevalue = element. getattribute (attributename)
Returns the value of a given attribute node for a given element.
10 getelementbyid ()
Element = Document. getelementbyid (ID)
Searches for an element with a given ID attribute value and returns an element node.
11 getelementbytagname ()
Used to find all elements with a signature for the calibration:
Elements = Document. getelementsbytagname (tagname)
Returns a node set.
12 haschildnodes
Used to check whether a given element has subnodes.
Booleanvalue = element. haschildnodes
Returns true or false.
13 Dom attributes
Node attributes
The nodename attribute returns a string whose content is the name of the given node.
If the node is an element node, the name of the element is returned;
If it is an attribute node, the name of this attribute is returned;
If it is a text node, a string whose content is # text is returned;
The nodetype attribute returns an integer that represents the type of the given node.
The nodevalue attribute returns the current value of the given node.
If the node is an element node, null is returned;
If it is an attribute node, the name of this attribute is returned;
If it is a text node, the content of the text node is returned;
Traverse node tree
Childnodes this attribute returns an array consisting of subnodes of the given Element Node
Firstchild returns the first subnode
Lastchild returns the last subnode
Nextsibling returns the next subnode of a given node.
Parentnode returns the parent node of a given node.
Previussibling returns the next subnode of the given Node ??
14 setTimeout
A JavaScript function allows a function to be executed after a certain period of time. The function has two parameters. The first parameter is the name of the function to be executed;
The second parameter is a value. In milliseconds, it sets how long it takes to start executing the function provided by the first parameter:
SetTimeout ("function", interval );