Element.remove()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Element.remove()
方法,把对象从它所属的 DOM 树中删除。
语法
js
remove()
示例
使用 remove()
html
<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>
<div id="div-03">Here is div-03</div>
js
var el = document.getElementById("div-02");
el.remove();
// id 为 'div-02' 的 div 被删掉了
Element.remove()
是不可见的
在 with
语句中,remove()
方法是不可见的。参阅 Symbol.unscopables
了解更多信息。
js
with (node) {
remove();
}
// ReferenceError: remove is not defined
规范
Specification |
---|
DOM # ref-for-dom-childnode-remove① |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
remove |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
ChildNode
纯接口。- 实现此纯接口的对象类型:
CharacterData
、Element
, 和DocumentType
.