spacer
Yehuda Shiran August 12, 2000
The Four Different inner/outer text/html Combinations
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

You can change HTML containment elements (such as DIV and SPAN) on the fly by using one of the following four properties: innerText, outerText, innerHTML, and outerHTML. The following table summarizes the differences between these four properties:

PropertyContent
innerTextThe textual content of the container.

outerTextSame as innerText when accessed for read; replaces the whole element when assigned a new value.

innerHTMLThe complete content of the container, not including the element tag pair itself.

outerHTMLThe complete container, including the element tag pair itself.

The following script demonstrates these properties:

<DIV ID="test"><B>This is a demo for inner/outer text/html combinations</B></DIV>
<SCRIPT LANGUAGE="JavaScript">
alert("InnerText is: " + test.innerText);
alert("OuterText is: " + test.outerText);
alert("InnerHTML is: " + test.innerHTML);
alert("OuterHTML is: " + test.outerHTML);
</SCRIPT>

The first alert box demonstrates the innerText property:

The second alert box demonstrates the outerText property:

The third alert box demonstrates the innerHTML property:

The fourth alert box demonstrates the outerHTML property:


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger