JavaScript Advanced Programming Reading Notes (10th Chapter DOM)

Source: Internet
Author: User

10th Chapter DOM

10.1 Node Hierarchy

Each node has a NodeType property that indicates the type of the node. Any node type must be one of the following:

      • Node.element_node (1);
      • NODE. Attribute_node (2);
      • Node.text_node (3);
      • Node.cdata_section_node (4);
      • Node.entity_reference_node (5);
      • Node.entity_node (6);
      • Node.processing_instruction_node (7);
      • Node.comment_node (8);
      • Node_document_node (9);
      • Node.document_type_node (10);
      • Node.document_fragment_node (11);
      • Node.notation_node (12);

Each node has a Childnoes property, and a NodeList object is saved. NodeList is a class array object that holds a group of ordered nodes.

Each node has a ParentNode property that points to the parent node in the document tree.

Each node in the childnodes is a sibling node. You can access it by using the PreviousSibling and NextSibling properties. The previoussibling of the first node in the list and the nextsibling of the last node are null.

The FirstChild and LastChild properties of the parent node point to the first and last nodes in ChildNodes, respectively.

Ownedocument represents the document node for the entire document.

AppendChild is used to add a node to the end of the ChildNodes list and to return the new node.

The InsertBefore () method accepts two parameters: the node to be inserted and the node to use as the reference. If the reference point is null, InsertBefore () and AppendChild () perform the same operation. Returns the newly inserted node.

The ReplaceChild () method accepts two parameters: the node to be inserted and the node to be replaced, which returns the node to be replaced.

RemoveChild () Removes the node and accepts a parameter: the node to remove. Returns the node that was removed.

The CloneNode () user creates an identical copy of the node that calls this method. The method accepts a Boolean parameter if True indicates that a deep copy is performed, representing the entire child node tree of the replication node machine. No parent node, equivalent to an orphan

The document node has the following characteristics:

      • The value of NodeType is 9
      • The value of NodeName is "#document"
      • The value of NodeValue is null
      • The value of parentnode is null
      • The value of ownerdocument is null

Document.documentelemenet is an HTML element

Document.body is the BODY element

getElementById () getelementbytagname ();

A node of type text has the following characteristics:

      • The value of NodeType is 3
      • The value of NodeName is "#text"
      • The value of NodeValue is the text that the node contains
      • ParentNode is an element
      • No child nodes, no support

Comment Type

The comment node has the following characteristics:

      • The value of NodeType is 8
      • The value of NodeName is "#comment"
      • The value of the NodeValue is the content of the comment;
      • ParentNode may be document or element
      • Child nodes are not supported

You can also create annotation nodes by using document.createcomment () and passing comment text for it.

JavaScript Advanced Programming Reading Notes (10th Chapter DOM)

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.