DOM Element.outerHTML Property
The outerHTML property gets the HTML of an element including its own tag, or replaces the whole element when set.
Description
The outerHTML property returns the HTML of the element including its own opening and closing tags. Setting it replaces the element in the page with the parsed markup; your variable still refers to the old, now-detached element. The same security caution as innerHTML applies.
Setting outerHTML throws an error for the <html> element and elements without a parent, since there's nothing to replace them in. Any event listeners on the old element and its children are lost, because new elements are created from the markup.
Reading it is handy for debugging, logging and copying an element's markup. To replace an element safely with new nodes, without parsing HTML strings, use replaceWith().
Syntax
element.outerHTML
element.outerHTML = htmlStringValue
A string of the element's HTML, including the element itself. Setting it replaces the element.
Example
Browser Support
The following information will show you the current browser support for the Element.outerHTML property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





