Home  >  Article  >  Web Front-end  >  What is the document object in html? An article to let you understand the document object

What is the document object in html? An article to let you understand the document object

寻∝梦
寻∝梦Original
2018-09-01 13:59:338934browse

This article mainly introduces the explanation of the HTML document object, as well as the analysis of usage examples of the HTML document object. Next, let us look at this article together.

First of all, let’s Let’s introduce the document object in HTML:

The document object (document) represents the document in the browser window. This object is a sub-object of the window object, because the window object is the default in the DOM object model. Object, so methods and sub-objects in the window object do not need to be referenced using window.

You can access any HTML tag contained in the HTML document through the document object and dynamically change the content in the HTML tag.

For example, forms, images, tables, hyperlinks, etc.

Let’s take a look at the collection of Document objects in HTML:

What is the document object in html? An article to let you understand the document objectLet’s take a look at the online description of document objects in HTML:

HTMLDocument interface extends the DOM Document interface and defines HTML-specific properties and methods.

Many properties and methods are HTMLCollection objects (actually read-only arrays that can be indexed by array or name), which hold references to anchors, forms, links, and other scriptable elements.

These collection attributes are derived from level 0 DOM. They have been superseded by Document.getElementsByTagName(), but are still often used because they are convenient.

The write() method is worth noting because it allows a script to insert dynamically generated content into the document while the document is loading and parsing.

Note that in the level 1 DOM, HTMLDocument defines a very useful method called getElementById(). In the level 2 DOM, this method has been moved to the Document interface, and it is now inherited by HTMLDocument rather than defined by it.

Next, give an example of using the HTML document object:



PHP中文网


欢迎!

上面的例子使

Use the document object to check the document title and display the title in the message box (if it is not empty ). if(document.title!="")alert("title is " document.title) The following example demonstrates an event handler function that displays the current position of the mouse on the browser's status bar, relative to the upper left corner of the document.

The above is the introduction and usage examples of this article about the HTML document object, so that you can have a clearer understanding of the HTML document object. If you have any questions, you can ask below.

【Editor's Recommendation】

How to set the font size of the font tag in html? Introduction to the usage of html font tag attribute

What is the code for adding images in HTML? How to add image path correctly in html?

The above is the detailed content of What is the document object in html? An article to let you understand the document object. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn