JavaScript Learning Basic Notes DOM object manipulation _javascript Tips

Source: Internet
Author: User
Tags xml dom document
The DOM Document Object model is an application interface (API) for HTML and XML, and the DOM plans the entire page as a document composed of node hierarchies. DOM objects give developers access to HTML and enable developers to process and view HTML as XML documents. A DOM object is a language-independent API, meaning its implementation is not bound to JavaScript, which may be misunderstood by beginners. Dom is a tree based API for XML that focuses not only on parsing XML code, but on representing it with a series of interrelated objects that can be modified and accessed directly without having to parse the code again. Because the DOM is easy to use, it becomes the favorite way for Web browsers and JavaScript. The Document object is an object of the BOM, that is, window.document==document, but it also belongs to the DOM and is also a representation of the HTMLDocument object of the HTML DOM, which is also the XML DOM Document object.

Most of the processing Dom in JavaScript is the use of the Document object.

To access HTML elements, you can take advantage of the documentelement attributes of document:

var ohtml=document.documentelement;

The Ohtml object contains a HtmlElement object that represents the
var ohead=ohtml.firstchild;

var obody=ohtml.lastchild;

You can get objects that represent
var ohead=ohtml.childnodes[0];//uses childnodes as an array;

var obody=ohtml.childnodes[1];//uses childnodes as an array;

The above expression can use more formal expression, that is Shiyongitem () method:

var ohead=ohtml.childnodes.item (0);

var obody=ohtml.childnodes.item (1);

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

Obody = document.body;

But Document.head is not defined, and its return value is undefined;

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.