Dynamically changed DHTML operations for web page content

zhaozj2021-02-16  53

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: