XML Responses and AJAX - A brief explanation of innerHTML (Page 2 of 5 )
We will be coming across the innerHTML property of a DOM object often. To understand this property, consider the following script. The document's p tag is grabbed by referencing its Id property using the getElementById() method. Make sure the syntax is correct; it is case sensitive and unforgiving. The next statement writes the innerHTML property of the referenced element as well as the InnerText property. The innerHTML property represents everything referenced by the Id reference including the mark up, that is in this case, The is a: monkey, whereas the InnerText property gets all the text after removing other tags, in this case, This is a: monkey as shown in the next picture.
<SCRIPT LANGUAGE="JavaScript"> function explain(){ var inT = document.getElementById("two"); document.write( "inner HTML: " + inT.innerHTML+ "<hr width='40%' align='left'>innerText: " + inT.innerText); } </SCRIPT>
<BODY> <p id="two">This is a: <b>monkey</b></p> <input type="button" value="test" onClick="explain()">