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
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: