Document Object for HTMLDOM series tutorials

Source: Internet
Author: User
Today, let's take a look at the document object in HTMLDOM, which we often mention. So what is a document object? In fact, each HTML document loaded into the browser

Today, let's take a look at the document object in html dom, which we often mention. What is a document object? In fact, every HTML document loaded into the browser will become a document Object. The document object allows us to access all elements in the HTML page, such as the commonly used docuemnt. getElementById (), document. getElementsByTagName. Document objects can be divided into three parts: document Object collection, document object attributes, and document Object methods. Next we will learn about them one by one.

Document Object set

All []: Access to all elements in HTML documents, but it is not W3C standard and FireFox does not support it.

For example, to obtain the Tag Name of the first element on the page:

1234567891011121314151617181920 Document Object _ BeyondWeb.cn
Var all = document. all; alert (all [0]. tagName); script

Anchors []: returns the reference of all the anchors in the document, as shown in figure

123456789101112131415161718192021222324252627 Document Object _ BeyondWeb.cn
  • HHHHHH
  • HHHHHH
  • HHHHHH






Var anchors = document. anchors; alert ("the number of anchors in the page is:" + anchors. length); script

Forms []: returns all form object references in the document.

Syntax: document. forms

Returns the number of all forms on the page. document. forms. length

Images []: returns all images object references in the document.

Syntax: document. images

Links []: returns all link object references in the document.

Syntax: document. links

Document Object Attributes

Body attribute: document.bodydirectly implements body, but there is a certain compatibility, which is usually used together with document.doc umentElement. If we want to obtain a high visible area of the webpage, we will do this best:

Var clientHeight = document.doc umentElement. clientHeight | document. body. clientHeight;

Cookie attribute: set or return all cookies related to the current document, as follows:

1234
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.