Differences between innerHTML, outerHTML, innerText, and outerText

Source: Internet
Author: User
Beginners may be confused about innerHTML, outerHTML, innerText, and outerText. Here we will explain: innerHTML & amp; nbsp; Sets or obtains & amp; nbsp; located in the start and end tags of the object; HTML & amp; n

Beginners may be confused about innerHTML, outerHTML, innerText, and outerText:
InnerHTML sets or obtains the HTML in the start and end tags of an object.
OuterHTML sets or obtains the HTML format of the object and its content
InnerText sets or obtains the text in the object's start and end labels.
OuterText setting (including tags) or obtaining (excluding tags) the text of an object

The differences between innerHTML and outerHTML are well understood:
But not many people know the differences between innerText and outerText. Let's look at the following code:

 
  
Fieldset content
  Span content -phpddt.com
 

If you only obtain the text in the tag, it is obvious that the values of innerText and outerText are the same. The preceding example is used to describe:
 

From the test, we can see the difference between innerText and outerText. innerText converts all the content of the label into text, and outerText replaces the entire including label with text.
Note: In addition, innerHTML is usually used during development, because innerText has poor compatibility.

Related Article

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.