1, function Explanation:
InnerHTML Sets or gets the HTML that is located within the start and end tags of the object
outerHTML Sets or gets the HTML form of an object and its contents
InnerText set or get text that is within the start and end tags of an object
Outertext set (including tags) or get (excluding tags) the text of an object
2. Example
<title>Demo</title>
<style><!--
Body {font-family: "Song Body"; color= "Blue"; font-size= "9pt"}
-</style>
<script language= "JavaScript" >
. InnerHTML
function Innerhtmldemo ()
{
Test_id1.innerhtml= "<i><u> set or get html.</u></i> located within the start and end tags of the object";
}
. innerText
function Innertextdemo ()
{
test_id2.innertext= "<i><u> Sets or gets the text .</u></i> located within the start and end tags of the object";
}
. outerhtml
function Outerhtmldemo ()
{
Test_id3.outerhtml= "<i><u> Sets or gets the HTML form of the object and its contents .</u></i>";
}
. outertext
function Outertextdemo ()
{
Test_id4.outertext= "<i><u> set (including tags) or get (excluding tags) the text of the object .</u></i>";
}
</script>
<body>
<ul>
<li id= "Test_id1" onclick= "Innerhtmldemo ()" >innerhtml effect .</li>
<li id= "Test_id2" onclick= "Innertextdemo ()" >innertext effect .</li>
<li id= "Test_id3" onclick= "Outerhtmldemo ()" >outerhtml effect .</li>
<li id= "Test_id4" onclick= "Outertextdemo ()" >outertext effect .</li>
</ul>
</body>
3, the difference:
The difference between innerHTML and outerHTML, innertext and Outertext is simply that:
1), innerHTML, and outerhtml the HTML that is included when setting the content of the object is parsed, and innertext and outertext do not.
2), when set, innerHTML and innertext only set the text within the label, while outerHTML and Outertext set the text including the label.
Special Note:
innerHTML is a standard-compliant attribute, and innertext only works with Internet Explorer, so use innerHTML as much as possible, and less innertext, if you want to output content that does not contain HTML tags, You can use innerHTML to get content that contains HTML tags, and then use regular expressions to remove the HTML tags, and here's a simple example of the standard:
<a href= "Javascript:alert (document.getElementById (' Test '). Innerhtml.replace (/<.+?>/gim, '))" > No HTML, Meet the Standards </a>
JavaScript InnerHTML, outerHTML, InnerText, outertext differences (RPM)