This article introduces some common methods of DOM and javascript!
1. Differences among innerText, innerHTML, outerText, and outerHTML
Function:
InnerHTML sets or obtains the HTML in the object's start and end tags.
OuterHTML sets or obtains the HTML format of the object and its content.
InnerText sets or retrieves the text in the object's start and end labels.
OuterText settings (including tags) or get (excluding tags) The text of the object.
Example:
Label <div id = "test"> <B> hello world! </B> </div> as an example:
The content displayed in innerText is: hello world!
The content displayed in innerHTML is: <B> hello world! </B>
The content displayed in outerText is: hello word!
The content displayed in outerHTML is: <div id = "test"> <B> hello world! </B> </div>
Description
InnerHTML is W3C standard and supports various browsers, while innerText, outerText, and outerHTML are unique to IE. In FF, you can replace innerText with textContent.
2. document. readyState
Function
Determine the Download Status of the page
Example
Document. onreadystatechange = function ()
{
If (document. readyState = "complete ")
{
// Do something;
}
}
Description
This attribute is only available in IE.
3. insertAdjacentHTML
Function
You can insert html content and text content in a specified place.
Example
<Html>
<Head>
<Script language = "javascript">
Function test (){
Var obj = document. getElementById ("test ");
Obj. insertAdjacentHTML ("afterEnd", "<br> <input name = \" a \ "> ");
}
</Script>
</Head>
<Body>
<Input id = "test" name = "test" type = "text" value = "" onclick = "test ()">
</Body>
</Html>
Description
FF does not have this attribute.