Basic javascript learning notes-DOM object operations

Source: Internet
Author: User
Tags xml dom document

The DOM Document Object Model is an HTML and XML application interface (API). DOM plans the entire page as a document composed of nodes. DOM objects give developers access to HTML, and enable developers to process and view HTML as XML documents. The DOM object is a language-independent API, which means that its implementation is not bound to javascript. This means that beginners may understand the error. DOM is a tree-based API for XML. It focuses not only on Parsing XML code, but on expressing the code with a series of correlated objects, which can be modified, in addition, you do not need to parse the code again to directly access them. Because DOM is easy to use, it becomes the favorite method of Web browsers and javascript. The documentobject is a bomobject, that is, the uploaded Doc ument = document, but it also belongs to DOM, which is also a form of representation of the html dom HTMLDocument object. In other words, it is also an xml dom Document Object.

Most of the DOM processing in JavaScript uses the document Object.

To access html elements, you can use the documentElement feature of document:

Var ohtml#document.doc umentElement;

The oHtml object contains an HTMLElement object that represents
Var oHead = oHtml. firstChild;

Var oBody = oHtml. lastChild;

You can get the objects that represent
Var oHead = oHtml. childNodes [0]; // use childNodes as an Array;

Var oBody = oHtml. childNodes [1]; // use childNodes as an Array;

The above expression can be more formal, that is, the shiyongitem () method:

Var oHead = oHtml. childNodes. item (0 );

Var oBody = oHtml. childNodes. item (1 );

In fact, the DOM object on the HTML page defines document. body as a pointer to the <body/> element, that is

OBody = document. body;

However, document. head is not defined, and its return value is undefined;

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.