IE's DHTML object provides four readable and writable properties to dynamically operate page elements: InnerText, Outertext, InnerHTML, OuterHTML.
Need to pay attention to two points:
1. The value of innerText, OUTERTEXT attribute is presented as a normal text, even if it contains an HTML tag, the innerhtml, OuterHTML presented the HTML engine to parse the text, it can react the performance of the HTML tag in attribute .
2. Assign the object to the Outertext, OuterHTML property of the object (ie, write) will delete the object.
The assignment operation of the above four attributes is just the text content of the original object. If you want to add text content in the page, you need to use the INSERTADJACENTHTML and INSERTADJACENTTEXT methods. The form is as follows:
Object.insertadjacentText (Swhere, Stext)
Object.insertadjacenthtml (Swhere, Stext)
Swhere indicates the position of the inserted text relative to the HTML tag, there is the following four preset values:
BeforeBegin, Afterbegin, Beforeend, Afterend
Be careful not to use the following:
1. These two methods must be used after the entire document is loaded, otherwise it will be wrong.
2. INSERTADJACETTEXT can only insert ordinary text, INSERTADJACENTHTML inserts text in HTML format
3. Insert scripts with INSERTADJACENTHTML, you must use the defer attribute in the Script element, otherwise the script execution will occur error
4. After INSERTADJACENTHTML is inserted into the HTML element, all, and other possible elements set will automatically update to react dynamic changes. The SourceIndex property of the next subsequent element will change.
5. This method may have a runtime error when it gives an INSERTHTML / OTERHTML attribute. If the following code will be wrong:
P>
PDIV.INNERHTML = "
Hello P>"
Script>
Body>
In addition, page content dynamic operations also need to pay attention to some details:
1. Only the content displayed in the document fody can be dynamically changed by the above attributes and methods, and the content of the Body object can be dynamically operated, but the Body object itself cannot be replaced.
2. The above properties and methods cannot operate the air tag (HTML tag without content), such as Input, IMG.
3. For Table objects, only TD (InnerHTML / Innertext) and Table (OuterHMTL / OUTERTEXT) objects can be replaced or inserted with certain properties; while other Table objects, such as TR, TBODY cannot use these attributes to change content.
Translation is organized from MSDN, the original reference Dynamic Content