Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:43:14
Original
1526 people have browsed it
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






Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template