A summary of node action learning in JavaScript

Source: Internet
Author: User
Tags tag name

Node:
1. In the HTML DOM (Document Object model), each section is a node:
The document itself is a document node
All HTML elements are element nodes
All HTML attributes are attribute nodes
Text within an HTML element is a text node
Comment is a comment node
2. Node Properties:
Element.childnodes returns the NodeList of the element child node
Element.classname Sets or returns the Class property of an element
Element.firstchild returns the first child node of an element
Element.lastchild returns the last child element of an element
Element.nextsibling return to the next sibling node
Element.previoussibling return to the previous sibling node
Element.nodename returns the name of the element
Element.nodetype the node type of the returned element
Element.nodevalue setting or returning element values
Element.parentnode returns the parent node of the element
Nodelist.item () returns the node at the specified subscript in the NodeList
Nodelist.length returns the number of nodes in the NodeList
Element.firstelementchild first element node
Element.firstChild.textContent text in the first child node
3. Properties:
Node Chinese type (NodeType) nodename node honour point value (NodeValue)
Element 1 TagName NULL
Property 2 attr Property value
Text 3 #text Text value
Note 8 #comment Comment text
Document 9 #docment NULL
4. New node:
(Added on last side of parent node)
1. new element; var a=document.createelement ("tag name");
2. New text: var b=documnet.createtextnode ("Content text");
3. New element text: A.appendchild (b);
4. Get parent node: var C=document.getelementbyid ("id parent");
5. New Tags: c.appendchild (a);

The second Method InsertBefore () (Adds a new node before specifying the existing child nodes):
5. Get the child node of the Add location: var D=document.getelementbyid ("id sub");
6.c.insetbefore (A,D);

5. Delete the node:
1. Get Delete node: var A=document.getelementbyid ("id delete");
2. Get the parent node: Var B=document.getelementbyid ("id parent");
3. Deletion: B.removechild (a);
The second type:
A.parentnode.removechild (a);
6. Replace the node:
Parent.replacechild (The new child node, the child node to be replaced);
7. Clone a node:
The CloneNode ("Ture/flase") method clones all properties and their values
CloneNode ("ture") clone nodes and their attributes, and descendants
CloneNode ("Flase") clone nodes and their descendants
1. Get the node to clone: Var A=document.getelementbyid ("id");
2. Clone: Var b=a.clonenode (true);
3. Add: C.appendchild (b);

8. Actions on the style sheet:
1. Internal embedding: <div style= "color: #f00" > Inline style </div>
<script type= "Text/javascript" >
document.getElementById (' Test '). Style.color = ' #000 ';
</script>
2. The external style sheet can only be read and cannot be modified





A summary of node action learning in JavaScript

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.