JavaScript DOM methods and properties summary

Source: Internet
Author: User
Tags numeric value

1 createelement (Element)
Creates a new element node with the specified label name, and the return value is a reference pointer to the new element node.
EG) var para = document.createelement ("P");
Document.body.appendChild (para);

2 createTextNode ()
Creates a new text node that contains the given text, and returns a reference pointer to the new text node:
Reference = document.createTextNode ()
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)
Creates a copy for a given node with either a parameter of TRUE or false,true indicating that the node is replicated at the same time, false does not replicate any child nodes.
var para = document.createelement ("P");
var message = document.createTextNode ("Hello World");
Para.appendchild (message);
Document.body.appendChild (para);
var Newpara = Para.clonenode (true);
Webjx.com


Document.body.appendChild (Newpara);

4 AppendChild ()
Reference = Node.appendchild (newchild);
Insert node, example reference front.

5 InsertBefore ()
Reference = Element.insertbefore (Newnode,targetnode)
Inserts a given node in front of a given child node of a given element node, returning a reference pointer 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 child node from a given element, returning a reference pointer to a child node that has been deleted.
When a node is deleted by RemoveChild (), all child nodes of this node are deleted.

7 ReplaceChild ()
Reference = Element.replacechild (Newchild,oldchild)
To replace a child node in a given parent element with another node, the Oldchild node must be a child of element elements, and the return value is a point that points to the replaced
The reference pointer for the child node.
Web Teaching Network

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);
Adds a new property value to the given element node or changes its existing properties

9 GetAttribute
AttributeValue = Element.getattribute (AttributeName)
Returns the value of a given attribute node for a given element.

Ten getElementById ()
element = document.getElementById (ID)
Looking for an element with a given ID attribute value, returning an element node

One getelementbytagname ()
Used to find all elements with a given sign signature:
elements = document.getElementsByTagName (TagName)
Returns a collection of nodes.

HasChildNodes
Used to check whether a given element has child nodes
Booleanvalue = Element.haschildnodes
Returns TRUE or FALSE.

Dom Property
The properties of the node
The NodeName property returns a string whose contents are the name of the given node.
Webjx.com


If the node is an element node, returns the name of the element;
If it is an attribute node, returns the name of the property;
If it is a text node, returns a string with #text content;

The NodeType property returns an integer that represents the type of the given node
The NodeValue property returns the current value of the given node
Returns null if the node is an element node;
If it is an attribute node, returns the name of the property;
If it is a text node, return the contents of the text node;

Traversing the node tree
ChildNodes This property returns an array of child nodes of a given element node
FirstChild returns the first child node
LastChild returns the last child node
NextSibling returns the next child node of a given node
ParentNode returns the parent node of a given node
PreviousSibling returns the next child node of the given node??

SetTimeout
JavaScript functions, which allow a function to begin executing after a predetermined period of time, with two parameters, the first parameter being the name of the function to be executed;
The second parameter is a numeric value, in milliseconds, setting how long it takes to begin executing the function given by the first parameter:
SetTimeout ("function", interval);

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.