HTML DOM outerHTML Property
Example
Change a header element and it's content:
document.getElementsByTagName("h1").outerHTML = "<h3>Header
Changed!</h3>";
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The outerHTML property sets or returns the HTML element and all it's content, including the start tag, it's attributes, and the end tag.
Browser Support
Property | |||||
---|---|---|---|---|---|
outerHTML | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the outerHTML property:
Element.outerHTML
Set the outerHTML property:
Element.outerHTML = text
Property Values
Value | Description |
---|---|
text | Specifies the new HTML contentt |
Technical Details
Return Value: | A String, representing the HTML content of an element, including the start end the end tag |
---|
More Examples
Example
Alert the outer HTML of a <h1> element:
var x = document.getElementsByTagName("h1")[0].outerHTML;
alert(x);
Try it Yourself »
❮ Element Object