The outer HTML of an HTML element is that fragment of HTML that completely contains the start and end tags of the element. The outerHTML of an <A> tag would be the complete anchor and any styled text or image tags between the <A> and </A> tags.
You can read this value to extract a fragment of HTML and you can write to this value to redefine a section of HTML within the page.
Because this property is not DOM compliant, you may want to refer to the DOM Text object and DOM CharacterData object which provide a compliant set of accessors to the content of a DOM component. The implementation of this is still somewhat vague and ambiguous and some more work needs to be done to bring the DOM compliant capabilities up to the same level of functionality. This can probably best be simulated by walking up the tree to a containing element and using innerHTML on that object.
Be careful if you extract the outerHTML 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.
If you replace the outer HTML, you will also be replacing the containing tags of the object. If you do not keep the ID or NAME properties intact, you may not be able to locate the object again in the way you might expect to later.
Conceptually, changing the outerHTML property of an object might imply that the object's class is being changed as well. This is not truly consistent with the rules of object oriented programming as you would not normally 'cast' objects in the way you might 'cast' pointers in the C-Language context. The effects of this are not documented and you may find that the behavior varies from one implementation to another.
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.onevent | Up | Element.outerText |
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. |