HTML node-related data collation _javascript tips

Source: Internet
Author: User
One, the HTML dom is a tree-shaped object

Two, each node contains some information about the nodes, respectively:

1. nodename
The NodeName property contains the name of a node.

* The nodename of the element node is the label name
* The nodename of the attribute node is the property name
* The nodename of the text node is always #text
* The nodename of the document node is always #document

Note: The label name of the XML element contained in NodeName is always uppercase

2. NodeValue

For text nodes, the NodeValue property contains text.

For an attribute node, the NodeValue property contains the property value.

The NodeValue property is not available for document nodes and ELEMENT nodes.

3. NodeType

The NodeType property can return the type of the node.

The most important node types are:
element Type Node Type
Elements 1
Property 2
Text 3
Comments 8
Document 9
Third, modify the node

1. [Newfathernode].appendchild ([Childnode])

This action changes the relationship between Newfathernode and Childnode as a parent-child node and automatically causes Childnode Oldfathernode not to own this Childnode node.

2. [Newfathernode].removechild ([Childnode])


Iv. Program Examples
Copy Code code as follows:

<body>
<div id= "Div1" >
<div id= " Div3 ">
</div>
</div>
<div id=" Div2 ">
</div>
<script>
function $id (ID) {
return document.getElementById (ID);
}

Function Countnodes (arr) {
var len = arr.length;
var i = 0;
while (len--) {
(arr[len].nodetype==1) && i++;
}
Return i;
}

Window.onload = function () {
Alert (countnodes ($id ("Div2"). childnodes));
$id ("Div2"). AppendChild ($id ("Div3"));
Alert (Countnodes ($id ("Div1"). childnodes));
Alert (Countnodes ($id ("Div2"). childnodes));
}
</script>
</body>

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.