This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

outerHTML

Property of dom/HTMLElementdom/HTMLElement

Syntax

var result = element.outerHTML;
element.outerHTML = value;

Examples

This example uses the outerHTML property to copy an object, accompanying attributes, and children to a list when a user clicks one of the objects.

<SCRIPT>
function fnCopyHTML(){
   var oWorkItem = event.srcElement;
   if((oWorkItem.tagName != "UL") && (oWorkItem.tagName != "LI")){
      alert("Adding " + oWorkItem.outerHTML + " to the list.");
      oScratch.innerHTML += oWorkItem.outerHTML + "<BR>";
   }
}
</SCRIPT>

<UL onclick = "fnCopyHTML()">
<LI><B>Bold text</B>
<LI><I>Italic text</I>
<LI><U>Underlined text</U>
<LI><STRIKE>Strikeout text</STRIKE>
</UL>
<P>
<DIV ID = "oScratch" >
</DIV>

Notes

Remarks

The outerHTML property is read-only on the caption, col, colGroup, html, head, body, frameSet, tBody, td, tFoot, th, tHead, and tr objects. The property can be any valid string containing a combination of text and tags. When the property is set, the given string completely replaces the object, including its start and end tags. If the string contains HTML tags, the string is parsed and formatted as it is placed into the document. You can set this property only after the onload event fires on the window. When dynamically creating a tag using TextRange, innerHTML, or outerHTML, use script to create new events to handle the newly formed tags. Microsoft Visual Basic Scripting Edition (VBScript) is not supported. You can change the value of the title element using the title property. To change the contents of the table, tFoot, tHead, and tr elements, use the table object model. For example, use the rowIndex property or the rows collection to retrieve a reference to a specific table row. You can add or delete rows using the insertRow and deleteRow methods. To retrieve a reference to a specific cell, use the cellIndex property or the cells collection. You can add or delete rows using the insertCell and deleteCell methods. To change the content of a particular cell, use the innerHTML property. This property is accessible at run time as of Microsoft Internet Explorer 5. Removing elements at run time, before the closing tag has been parsed, can prevent other areas of the document from rendering.

Syntax

Attributions