Javascript: the Document Object Model (DOM)

Source: Internet
Author: User
Dom
  • 12 constants of the node type:
    • Node. element_node
    • Node. attribute_node
    • Node. text_node
    • Node. cdata_section_node
    • Node. entity_reference_node
    • Node. entity_node
    • Node. processing_instruction_node
    • Node. comment_node
    • Node. document_node
    • Node. document_type_node
    • Node. document_fragment_node
    • Node. notation_node
  • Node
    Methods/features: nodename, nodevalue, nodetype, ownerdocument, firstchild,
    Lastchild, childnodes, previussibling, nextsibling, haschildnodes (),
    Attributes, appendchild (node), removechild (node), replaceChild (newnode,
    Node), insertbefore (newnode, node ).
  • Htmlelement,
    For example, htmldivelement represents <div>
  • Document.doc umentelement = <HTML>,
    Document. Body = <body>
  • The attributes of element is actually namednodemap,
    You can perform the following operations: getnameditem (name), removenameditem (name ),
    Setnameditem (node), item (POS). [all these methods return an ATTR node]. shortcuts:
    • Getattribute (name)
      = Attributes. getnameditem (name). value.
    • Setattribute (name,
      Newvalue) = attribute. getnameditem (name). Value
    • Removeattribute (name)
      = Attribute. removenameditem (name ).
  • Access a specified node:
    • Getelementsbytagname ()
    • Getelementsbyname () [IE
      6. There are some errors in the implementation of this method in opera 7.5: 1. The element whose ID is equal to the given name will be returned. 2.
      They only check <input/> and elements]
    • Getelementbyid () [IE6 has similar bugs,
      ID, name regardless]
  • Create and operate nodes
    • Createelement (),
      Createtextnode (), appendchild ()
    • All Dom operations can only be performed after the page is completely downloaded, because the page is loading
      The DOM tree has not been fully built. Therefore, the onload event must be used.
    • Removechild (), replaceChild (),
      Insertbefore ()
    • Createdocumentfragment (). Avoid refreshing document multiple times.

 


HTML Dom features

 

  • Element. getattribute ("src ")
    = Element. SRC, element. getattribute ("border") = element. Border.
    The exception is class. Because class is a reserved word in ecmascript, element. getattribute ("class") =
    Element. classname.
  • Additional attributes of the table element.
    • <Table>:
      Caption, tbodies, tfoot, thead, rows, createthead (), createtfoot (),
      Createcaption (), deletethead/tfoot/caption (), deleterow (position ),
      Insertrow (position ).
    • <Tbody>: rows, deleterow (POS ),
      Insertrow (POS)
    • <Tr>: cells, deletecell (POS ),
      Insertcell (POS ).

 


Traverse dom
Nodeiterator (
Deep Search ):
  • Document. createnodeiterator (root, whattoshow,
    Filter, entityreferenceexpansion)
  • Whattoshow can be:
    • Nodefilter. show_all,
      Show_element, show_attribute, show_text, show_cdata_section,
      Show_entity_reference, show_entity, show_processing_instruction,
      Show_comment, show_document, show_document_type, show_document_fragment,
      Show_notation.
  • Iterator. nextnode (), previusnode ().
  • Nodefilter
    Subclass. acceptnode () is the only method. If it is displayed, nodefilter. filter_accpet is returned,
    The return value is nodefilter. filter_reject.

Treewalker
  • Inheritance
    Nodeiterator, added:

    • Parentnode ()
    • Firstchild ()
    • Lastchild ()
    • Nextsibling ()
    • Previussibling ()
  • Document. createtreewalker ()

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.