HTM DOM objects and the understanding of XML DOM objects

Source: Internet
Author: User

HTML is an XML-based document specification. is a special kind of XML document, which is important

1.xml document operation, java,c#,... Various languages provide a good API for parsing and manipulating documents. Of course JS is no exception, providing a series of methods.

The specific method, the world of all the explanation. Document,node, elementnode,textnode,attributenode,commentnode,nodelist These are the attributes of XML

Each node in the XML is a nodes object,

2.html is a special kind of XML document, so where is the special place?

1) HTML encapsulates a series of objects, such as Image,table,form,input,select ... Wait a minute

We can use the new Image () to create the object

Each node in the HTML is an element object,

2) HTML DOM provides a more convenient way to access nodes, Xxx.classname, xxxx.id, etc.

In a standard XML document, you should use Getatrribute () to access it. Of course the HTM DOM can also be accessed in this way because it is an XML

3. When loading HTML, the browser creates a global window object, then downloads the HTML document, creates the Document object, and assigns the document object to the Global Window object.

The document created here is HTMLDocument, and the HTMLDocument interface extends the DOM Document interface, defining HTML-specific properties and methods. In the new specification

The elements in HTML are all Htmlelment objects, and the HtmlElement object inherits the standard properties of the Node and element objects. That means span div. These nodes can use the node object and the method of the Element object

The XML DOM and the HTM DOM complement each other in their use,

4.tips

Document.getelmentsbytagname returns a dynamic nodelist, Document.queryseletorall () returns a static nodelist

Nodelist is an XML DOM attribute, and the above two methods also belong to the XML DOM.

dynamic refers to:

The three collections of Htmlcollection, NodeList, and NamedNodeMap are "dynamic", and they are updated whenever the document changes. They will always keep the latest and most accurate news. and see the following procedure:
var divs = document.getelementsbytagname ("div"), I, Div;                for (i = 0; i < divs.length; i++) {div = document.createelement ("div");            Document.body.appendChild (DIV); }
The above code is a dead loop!

Another htmlcollections is to return some htmlelement sets, such as the option under Select, the table element below the form, and so on.

Believe that with the above guiding ideology, in understanding a lot of methods, the model is very helpful

HTM DOM objects and the understanding of XML DOM objects

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.