Home  >  Article  >  Web Front-end  >  innerhtml usage innertext usage and the difference between innerHTML and innertext_javascript skills

innerhtml usage innertext usage and the difference between innerHTML and innertext_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:43:141475browse
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:
Copy code The code is as follows:

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
Copy code The code is as follows:











nothing






Statement:
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