Original: http://walsh.iteye.com/blog/261966
InnerHTML, innertext and outerhtml, outertext Difference Blog classification:
Html
1. The difference is described as follows:
- 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
InnerText and outertext are the same effect when they are acquired, but when set, innertext only sets the text within the label, and the outertext sets the text including the label.
2. Sample CodeHTML code
- <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd">
- < HTML >
- < Head >
- < Meta http-equiv="Content-type" Content= "text/html; Charset=utf-8 ">
- < title > the difference between InnerHTML, outerhtml and innertext, outerHTML </ title >
- < Script language="JavaScript" type=" Text/javascript ">
- . InnerHTML
- function Innerhtmldemo ()
- {
- test_id1.innerhtml = <i><u> set or get html.</u></i> in the start and end tags of the object ;
- }
- . innerText
- function Innertextdemo ()
- {
- Test_id2.innertext = <i><u> Sets or gets the text that is within the start and end tags of the object .</u></i> ;
- }
- . outerhtml
- function Outerhtmldemo ()
- {
- test_id3.outerhtml = "<font size=9pt color=red><i><u> Sets or gets the HTML form of the object and its contents .</u></i></font>" ;
- }
- . outertext
- function Outertextdemo ()
- {
- Test_id4.outertext = "<br></br><i><u> set (including tags) or get (excluding tags) the text of the object .</u></i>" ;
- }
- </ Script >
- </ Head >
- < Body >
- < ul >
- < li id = "TEST_ID1" onclick = "Innerhtmldemo ()" > The innerHTML effect. </ li >
- < li id = "Test_id2" onclick = "Innertextdemo ()" > The innertext effect. </ li >
- < li id = "TEST_ID3" onclick = "Outerhtmldemo ()" > The outerhtml effect. </ li >
- < Li id="Test_id4" onclick="Outertextdemo ()" >outertext effect. </ Li >
- </ ul >
- </ Body >
- </ HTML >
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > 3, the difference:In a nutshell, the difference between innerHTML and outerHTML, innertext and Outertext is that: 1), innerHTML, and outerhtml the HTML that is included in setting the object's content is parsed. and innertext and outertext are not. 2), when set, innerHTML and innertext only set the text within the label, while outerHTML and Outertext set the text including the label. For a DIV with an ID of "Testdiv", the difference between outerhtml, innerHTML, and innertext can be demonstrated by: