All the nodes and methods of JavaScript

Source: Internet
Author: User
Tags cdata manual writing object model tag name

Property:
List of properties for 1.Attributes storage nodes (read only)
List of child nodes of the 2.childNodes storage node (read only)
3.dataType returns the data type of this node
4.Definition definition of a node given in DTD or XML Schema (read-only)
5.DOCTYPE Specifies the document type node (read-only)
6.documentElement returns the root element of the document (Readable and writable)
7.firstChild returns the first child node of the current node (read-only)
8.Implementation return Xmldomimplementation Object
9.lastChild returns the last child node of the current node (read-only)
10.nextSibling returns the next sibling node of the current node (read-only)
11.nodeName returns the name of the node (read-only)
12.nodeType returns the type of the node (read-only)
13.nodeTypedValue Storage node value (readable and writable)
14.nodeValue returns the text of the node (readable and writable)
15.ownerDocument returns the root document containing this node (read-only)
16.parentNode returns the parent node (read-only)
17.Parsed returns whether this node and its child nodes have been parsed (read-only)
18.Prefix return namespace prefix (read-only)
19.PRESERVEWHITESPACE Specifies whether to preserve white space (readable and writable)
20.previousSibling returns the previous sibling node of this node (read-only)
21.Text returns the text content of this node and its descendants (readable and writable)
22.url returns the URL of the most recently loaded XML document (read-only)
23.XML returns the XML representation of the node and its descendants (read-only)

Method:
1.appendChild adds a new child node for the current node, placed after the last child node
2.cloneNode Returns a copy of the current node
3.createAttribute creates a new property
4. Createcdatasection Creating a CDATA segment that includes a given data
5.createComment creating a note node
6.createDocumentFragment creating a DocumentFragment Object
7.createelement_x Create an element node
8.createEntityReference Create EntityReference object
9.createNode Create a node of the given type, name, and namespace
10.createPorcessingInstruction Create action instruction node
11.createTextNode Create a text node that includes the given data
12.getElementsByTagName Returns a collection of elements of the specified name
13.hasChildNodes returns whether the current node has child nodes
14.insertBefore Insert a child node before the specified node
15.Load Import XML document at the specified location
16.loadXML Import XML document of the specified string
17.removeChild removes the specified child node from the child nodes list
18.replaceChild replaces the specified child node in the child node list
19.Save Save the XML file to the specified node
20. SelectNodes a specified match to the node and returns a matching node list
21.selectSingleNode matches the node with the specified match and returns the first matching node
22.transformNode Converts a node and its descendants using the specified style sheet
23.transformNodeToObject converts a node and its descendants to an object using the specified style sheet


DOM (Document Object model)
The introduction of the DOM (Document Object model) concept, this API makes HTML more powerful, but some of the DHTML friends are still somewhat sleepy, just because the current manual writing is not very scientific, is by the letter
To be divided, inconvenient to consult. In fact, the most important thing in DOM is to master the relationship between nodes and nodes (between node Andnode), want to learn the DOM in DHTML do not look through the
There are properties and methods, you have the Three Kingdoms when the Zhang Song of the "photographic" ability? No, listen to my analysis:
What Dom teaches us is a hierarchy, which you can understand as a tree structure, like our directory, a root directory, a subdirectory under the root directory, and a sub-directory with sub-directories.
Directory......
Root node:

The DOM calls each object in the hierarchy a node, as an example of HTML Hypertext Markup Language: a root of the entire document is <HTML>, which can be used in the DOM
Document.documentelement to access it, it is the root node of the entire node tree (root)
Child nodes:
In the general sense, the node below the root node is the main document area <body>, to access the body tag, in the script should write:
Document.body
All text and HTML tags within the body area are nodes of the document, called text nodes, element nodes (or tag nodes), and you know that HTML is just text,
No matter how the page must be composed of these two nodes, can only be composed of these two nodes
The relationship between nodes:
The relationship between nodes is also the most important one in the DOM, how to correctly refer to the node object, it is necessary to understand the node tree nodes of the mutual description of the way, in DHTML,
JavaScript scripts use a whole set of methods and properties of each node object to describe additional node objects.

Absolute references to nodes:
Returns the root node of the document
Document.documentelement
Returns the tag node that is being clicked in the current document
Document.activeelement
Returns the source node that the mouse moved out of
Event.fromelement
Returns the source node in which the mouse is moved
Event.toelement
Returns the source node of the activation event
Event.srcelement
Relative references to nodes: (Sets the current node to nodes)
Returns the parent node
Node.parentnode
Node.parentelement
Returns a collection of child nodes (containing text nodes and label nodes)
Node.childnodes
Returns a child label node collection
Node.children
Returns a collection of child text nodes
Node.textnodes
Returns the first child node
Node.firstchild
Returns the last child node
Node.lastchild
Returns the next node of the same genus
Node.nextsibling
Returns the same genus as the previous node
Node.previoussibling
The various operations of the node: (Set the current node to nodes)
New label node handle:
Document.createelement_x (SNode)//parameter is the node tag name to be added, example: newnode=document.createelement_x ("div");
1. Add a node:
Append child nodes:
Node.appendchild (Onode)//onode A new node handle for a living, for example: Node.appendchild (NewNode)
Apply Tag Node
Node.applyelment (Onode,swhere)//onode A new node handle, Swhere has two values: Outside/inside, added outside the current node or inside
Inserting nodes
Inode.insertbefore ()
Node.insertadjacentelement ()
Node.replaceadjacenttext ()
2, modify the node:
Delete a node
Node.remove ()
Node.removechild ()
Node.removenode ()
Replace node
Node.replacechild ()
Node.replacenode ()
Node.swapnode ()

2. Replication node:
Returns the replication Replication node reference
Node.clonenode (Ball)//ball is a Boolean value, true/false whether to clone all child nodes of the node
3. Node information
Whether to include a node
Node.contains ()
Whether there are child nodes
Node.haschildnodes ()
*******************************************************
The following is a JavaScript operation XML
<script language= "JavaScript" >
<!--
var doc = new ActiveXObject ("Msxml2.domdocument"); Ie5.5+,createobject ("Microsoft.XMLDOM")

Loading documents
Doc.load ("B.xml");
Create a file header
var p = doc.createprocessinginstruction ("xml", "version= ' 1.0 ' encoding= ' gb2312 '");
Add a file header
Doc.appendchild (P);
Get root contact for direct load
var root = doc.documentelement;
Create root contacts in two ways
var root = doc.createelement_x ("Students");
var root = Doc.createnode (1, "Students", "");
Create a sub-contact
var n = doc.createnode (1, "Ttyp", "");
Specify Child Contact text
N.text = "This is a test";
Create a grandchild Contact
var o = doc.createelement_x ("Sex");
O.text = "male"; Specify its text
Creating properties
var r = doc.createattribute ("id");
r.value= "Test";
Add Property
N.setattributenode (R);
Create a second property
var r1 = Doc.createattribute ("class");
R1.value= "TT";
Add Property
N.setattributenode (R1);
Delete Second Property
N.removeattribute ("class");
Add Sun Contacts
N.appendchild (o);
Add a text contact
N.appendchild (Doc.createtextnode ("This is a text node."));
Add Comment
N.appendchild (Doc.createcomment ("This is a comment\n");
Add a child contact
Root.appendchild (n);
Copy Contacts
var m = N.clonenode (true);
Root.appendchild (m);
Delete Contact
Root.removechild (root.childnodes (0));
Create a data segment
var c = doc.createcdatasection ("This is a CDATA");
C.text = "Hi,cdata";
Adding data segments
Root.appendchild (c);
Add Root Contact
Doc.appendchild (root);
Find Contacts
var a = Doc.getelementsbytagname_r ("Ttyp");
var a = Doc.selectnodes ("//ttyp");
Display the properties of the changed contacts
for (var i= 0;i<a.length;i++)
{
alert (a[i].xml);
for (Var j=0;j<a[i].attributes.length;j++)
{
alert (a[i].attributes[j].name);
}
}
modifying nodes, using XPath to locate nodes
var B = Doc.selectsinglenode ("//ttyp/sex");
B.text = "female";
alert (doc.xml);
XML save (required on the server side, client with FSO)
Doc.save ();
View Root junction XML
if (n)
{
alert (n.ownerdocument.xml);
}
-
</script>

All the nodes and methods of JavaScript

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.