test.innerHTML: That is, the entire content from the starting position to the ending position of the object, including the Html tag.
The value of test.innerHTML in the above example is "
test1 test2 ".
test.innerText: Content from the starting position to the ending position, but it removes the Html tag
The value of text.innerTest in the above example is "test1 test2", The span tag has been removed.
test.outerHTML: In addition to containing the entire content of innerHTML, it also contains the object tag itself.
The value of text.outerHTML in the above example is
test1 test2
Complete Example:
Special note:
innerHTML is an attribute that complies with W3C standards, while innerText is only applicable to IE browsers, so use innerHTML as much as possible , and use less innerText. If you want to output content without HTML tags, you can use innerHTML to obtain the content containing HTML tags, and then use regular expressions to remove the HTML tags. The following is a simple example that complies with W3C standards:
No HTML, compliant with W3C standards
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn