Set the outer text of an element:
document.getElementById("myH1").outerText = "Changed content!";
Try it Yourself »
The outerText property sets or returns the text content of the specified node.
This property is similar to the inner innerText property, in fact getting the outerText returns the same result as getting the innerText property.
There are an important difference when setting an element's outerText, because the element itself is removed.
Tip: also check out the outerHTML property.
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
outerText | 43 | 11 | Not supported | 6 | 61 |
Return the text content of a node:
node.outerText
Set the text content of a node (replacing the entire node):
node.outerText =
text
Value | Type | Description |
---|---|---|
text | String | Specifies the text content to insert |
Return Value: | A String, representing the text content of a node and all its descendants |
---|
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!