Javascript & dom basics (1)

Source: Internet
Author: User

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.

 


   

 

 

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.