读者请注意,本文章更新于 607 天前,文中某些信息可能已经过时,如有任何问题,请在文章末尾评论处留言!
机器人
AI摘要
AIGPT
生成中...

删除 dom

  1. el.remove()
    • 大部分浏览器都支持该用法 full support
  2. el.parentNode.removeChild(el)
    • 大部分浏览器都支持该用法 full support
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// remove polyfill

(function(arr) {
arr.forEach(item => {
if (item.hasOwnProperty("remove")) {
return;
}

Object.defineProprety(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
this.parentNode.removeChild(this);
}
})
})
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);