The HTML from the start tag to the end tag, including the tags that define the element, is extracted and any tags are removed. The resulting text is returned when this property is being read.
You can read this value to extract a fragment of text, and you can write to this value to redefine a section of text within the page.
When the property is being written to, the start and end tags are destroyed because everything between them and the tags is replaced with a text string. To place new HTML tags as replacements, for the ones you are about to destroy, use the outerHTML property.
DOM standardization provides access to the content of a Text and CharacterData object. These are special cases of the Node object which is also the parent of the Element object. We really need the Element object to inherit the data accessors of the CharacterData object as well and for now at least it doesn't. So long as you want to access text in between Element objects, you may be able to navigate the Node hierarchy and access properties of the Text objects between each Element.
Be careful if you extract the outerText of an element and document.write() it back to the same document. You can create recursive loop situations if you are evaluating in global code during the document loading process.
You cannot set this property while the document is loading.
It is not clear what the intent of this property is when used as an LValue. Assigning a new string to this property when it's on the left of an expression implies that the containing HTML tags could be removed. Some experimentation may be necessary to ensure you get predictable behavior across the various browser implementations. Removing the containing HTML tags could cause an object to be removed from the document tree and discarded. Because the container is no longer there, any child objects will also have been destroyed and there is no handle by which you can locate the object again because there is no HTML tag with a NAME or ID attribute to find.
If the implementation is smart, it will let you retain the parent object by reference, but will mutate it from an HTML Element that represents a tag and change it into a text node. That way you could then reassign some outerHTML to it to re-establish the HTML containment again.
MSIE version 4 for Macintosh does not support this as widely as the Windows version or later versions of MSIE for Macintosh.
Netscape does not support it at all.
Prev | Home | Next |
Element.outerHTML | Up | Element.ownerDocument |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |