Js-DOM programming Core

Source: Internet
Author: User

Common core DOM components:

DOM method

Create a node: createElement (), createTextNode ()

Replication node: cloneNode ()

Insert nodes: appendChild (), insertBefore

Delete node: removeChild ()

ReplaceChild ()

Find nodes: getAttribute (), getElementById (), getElementsByTagName, hasChildNodes

Set node attributes: setAttribute ()

DOM attributes

Node attributes: nodeName, nodeType, nodeValue

Traverse the node tree: childNodes, firstChild, lastChild, nextSibling, parentNode, previousSibling

The following is a brief usage of this part. An index is like a help document.

1.doc ument. createElement ("node name"): Creates a node.

2.doc ument. createTextNode ("text content"): Creates a text node.

3. node. cloneNode (true | false): copy the node. If the parameter is true, the node is copied together with the subnode. If the parameter is false, the subnode is not copied.

4. node. appendChild (subnode): Add a subnode under the node

5. parent node. insertBefore (new node, reference point): Insert a new node before the reference point under the parent node. Generally, the parent node is written as follows: reference point. parentNode

6. parent node. removeChild: deletes the specified child node under the parent node. All nested child nodes under the child node will be deleted.

7. parent node. replaceChild (new node, old node): replace the specified child node under the parent node with the new node.

8. node. getAttribute ("attribute name"): searches for the attribute name of a specified node and returns the attribute value of this attribute.

9.doc ument. getElementById ("id name"): searches for nodes with the specified id in the document and returns the Node object.

10.doc ument. getElementsByTagName ("tag name"): searches for the calibration signature node in the document. A Node object list (array) is returned. The base number starts from 0 and has the length attribute, indicating the length of the array.

11. node. hasChildNodes: indicates whether the node has a subnode. If yes, true is returned. If no subnode exists, false is returned (for example, text node and attribute node)

12. node. setAttribute ("attribute name", "attribute value"): adds an attribute to the node. If the attribute already exists, the attribute value is refreshed.

13. node. nodeName: differentiated by Node Type

Element Node: returns the Tag Name (equivalent to the tagName attribute)

Text node: return # text

Property node: returns the property name.

14. node. nodeType: Return node type. There are three types:

Element Node: return 1

Attribute node: 2 is returned.

Text node: 3 is returned.

15. node. nodeValue: return the current value of the node, which is differentiated by node type:

Element Node: return null

Property node: returns the property value.

Text node: return text content

16. node. childNodes: return all the first-level subnodes under the node (as described earlier, this attribute has different interpretations in different browsers)

17. node. firstChild: returns the first subnode under the node.

18. node. lastChild: return the last child node under the node.

19. node. nextSibling: returns the object of the next sibling node of the node.

20. node. parentNode: return the parent node of the node (it must be an element node, and the parent node of the document node is null)

21. node. previussibling: opposite to nextSibling, return the object of the previous sibling node of the node.

Articles you may be interested in
  • Comparison and Analysis of string encoding functions escape, encodeURI, and encodeURIComponent in javascript
  • Why is the php programming language very grassroots?
  • Website profit tips: how to turn every user into a core user
  • Div css book tutorials recommend "professional CSS + DIV webpage style and layout video tutorials"
  • Jquery get ($. get) event usage and Analysis
  • Download from Brother's php advanced programming video tutorial
  • JQuery DOM node insertion method summary
  • PHP generates continuous numbers (letters) Array Function range () analysis, PHP lottery program function

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.