HTML DOM Document

Source: Internet
Author: User

Document Object

Each HTML document that is loaded into the browser becomes the document object.

The Document object allows us to access all elements of an HTML page from within a script.

Tip: The Document object is part of the Window object and can be accessed through the Window.document property.

Document Object Collection
Collection Description
All[] Provides access to all HTML elements in a document.
Anchors[] Returns a reference to all Anchor objects in the document.
Applets Returns a reference to all Applet objects in the document.
Forms[] Returns a reference to all Form objects in the document.
Images[] Returns a reference to all the Image objects in the document.
Links[] Returns a reference to all area and Link objects in the document.
Document Object Properties
Properties Description
Body

Provides direct access to the <body> element.

For a document that defines a frameset, this property refers to the outermost <frameset>.

Cookies Sets or returns all cookies related to the current document.
Domain Returns the domain name of the current document.
LastModified Returns the date and time when the document was last modified.
Referrer Returns the URL of the document loaded into the current document.
Title Returns the title of the current document.
Url Returns the URL of the current document.
Document Object method
Method Description
Close () Closes the output stream opened with the Document.open () method and displays the selected data.
getElementById () Returns a reference to the first object that owns the specified ID.
Getelementsbyname () Returns a collection of objects with the specified name.
getElementsByTagName () Returns a collection of objects with the specified label name.
Open () Open a stream to collect the output from any document.write () or Document.writeln () method.
Write () Write an HTML expression or JavaScript code to the document.
Writeln () is equivalent to the Write () method, unlike writing a newline character after each expression.
Document Object Description

The HTMLDocument interface extends the DOM Document interface, defining HTML-specific properties and methods.

Many properties and methods are Htmlcollection objects (which are actually read-only groups that can be indexed with arrays or names), where references to anchors, forms, links, and other scriptable elements are saved.

These collection properties are derived from the level 0 DOM. They have been replaced by document.getElementsByTagName (), but they are still often used because they are convenient.

The Write () method is worth noting that when a document is loaded and parsed, it allows a script to insert dynamically generated content into the document.

Note that in the Level 1 DOM, HTMLDocument defines a very useful method named getElementById (). In the Level 2 DOM, the method has been transferred to the Document interface, which is now inherited by HTMLDocument rather than defined by it.

HTML DOM Document

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.