Document. Write

Source: Internet
Author: User
<HTML> 

Chrome performance in case of success or failure:

Document is initialized before the engine starts parsing the code. It is put into the scope and pushed to the end of the scope chain. However, the scope chain is empty at this time, so the document is at the top, that is, what we call global variables.
Initialization is similar to VaR document = new document ();
Document is a class with methods such as body, getelementbyid, getelementsbyname, and write.
Therefore, document has the prototype method of document and its member variables, but getelementbyid can only be used after the body has been loaded. This is why when the page is not loaded, we cannot use getelementbyid, but write does not, so we can call document before the page is loaded. write Method
We also know that the write method is used to specify the output of the object in the current document,
In fact, when the document. Write method is called, the open and close methods are called.
Document. open ();
Document. Write ();
Document. Close ();
When open is enabled, a document stream is opened to input the content. When the document already exists, it is cleared first.
Write is the written content, close is the closing of the Document Stream
In the preceding example, when document. when writing, the document does not exist, so it will not empty, but will directly attach the content to the Document Stream. When there is content appended to the document stream, the body will naturally be created. You can use the firebug breakpoint to clearly see the first document. the body is null before write, when document. after the write operation, the body will be "body". If it is a space or other elements, no body will be created, so the author resolves the document. you can use document. body. appendchild
However, we also remind you not to use document. Write unless necessary, because when window. onload is used, the document will be cleared.

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.