JavaScript Note 6-dom

Source: Internet
Author: User
Tags object model

The DOM (Document Object model) is an API for HTML and XML documents. The DOM depicts a hierarchical tree of nodes that allows programmers to add and modify parts of a page.

  1. Node hierarchy: The DOM can portray any HTML or XML document as a structure composed of multi-level nodes. Such as:
    • The document node has an only child: an HTML element.
    • Each element node is actually an object.
    • Elements, attributes of elements, and even annotations have their own nodes and the location of their respective nodes.
    • Therefore, there are many types of nodes, and these different nodes inherit from an underlying type: node type.
  2. All node types in
  3. node-type nodes
    • JavaScript are inherited from node types. So all node types have a subset of the same properties and methods.
    • Each node has a NodeType property that indicates the type of node. There are 12 constants stored in the Node object, representing 12 node types, respectively.
       for example: node.element_node=1; node.attribute_node=2; node.text_node=3; Node.comment_node=8, ..... The node type is judged by the nodeType of the node, for example: Somenode.nodetype==1, which indicates that the node is an element node. 
    • Each node has a ChildNodes property that holds a NodeList object that holds the child information for that node.

       and each child is a sibling. The PreviousSibling and NextSibling properties of each child node allow access to other sibling nodes. 
    • Each node has a ParentNode property that points to the parent node in the document tree.
    • Parent-child sibling diagram:
    • Each node has some of the same methods for manipulating nodes in addition to some of the same properties.
       appendchild (), add a child. InsertBefore (), add a child, and put it before a child. ReplaceChild (), replace a child. RemoveChild () to remove a child. 
  4. node of document type
    • The document node is the root node of the HTML node tree, representing the entire HTML interface.
    • The Document object is a property of the Window object in the BOM and can therefore be accessed as a global object.
    • The Document object has a body property that points directly to the <body> element.
    • The Document object has a title property that marks the caption of the documents (pages).
    • Find the elements within the document by getElementById (), Getelementbytagname ().
  5. Element type node
    • Each element has its own attributes (ID, name, class, and so on), and the methods to manipulate these properties are:
      GetAttribute (); SetAttribute (); RemoveAttribute ();
    • The Style property and the OnClick property cannot get an element through the GetAttribute () method.
  6. DOM2 and DOM3
    • The DOM1 level is primarily defined by the underlying structure of HTML and XML documents. DOM2, Level 3 introduces more interaction capabilities on the basis of this structure.
    • The purpose of DOM2, Level 3, is to extend the DOM API to meet the additional requirements of manipulating XML.
    • XML namespaces
      • With XML namespaces, the elements of different XML documents can be blended together without worrying about naming conflicts.
      • Namespaces are specified with the xmlns attribute.
      • The XHTML namespace is http://www.w3.org/1999/xhtml.
      • Any well-formed XHTML page will say namespaces are included.
      • namespaces Example:

JavaScript Note 6-dom

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.