Change the first h2 element and it's content:
document.getElementsByTagName("h2")[0] = "<h3>Changed!</h3>";
Try it Yourself »
Replace an element with a header:
element.outerHTML = "<h2>This is a h2 element</h2>";
Try it Yourself »
Alert the outer HTML of a <h1> element:
let html = document.getElementsByTagName("h1")[0].outerHTML;
alert(html);
Try it Yourself »
Alert the outer HTML of a <ul> element:
let html = document.getElementsByTagName("ul")[0].outerHTML;
alert(html);
Try it Yourself »
The outerHTML
property sets or returns the HTML element, including attributes, start tag, and end tag.
Return the outerHTML property:
element.outerHTML
Set the outerHTML property:
element.outerHTML =
text
Value | Description |
text | The new HTML content. |
Type | Description |
String | The HTML content of the element, including attributes, start tag and end tag. |
element.outerHTML
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!