IE 不支持 `HTMLElement.remove` 方法

IE 填坑记

  1. Can i use
  2. MDN ChildNode remove
  3. StackOverflow javascript-remove-doesnt-work-in-ie

PolyfillSection

You can polyfill the remove() method in Internet Explorer 9 and higher with the following code:

// from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('remove')) {
      return;
    }
    Object.defineProperty(item, 'remove', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function remove() {
        if (this.parentNode === null) {
          return;
        }
        this.parentNode.removeChild(this);
      }
    });
  });
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
posted @ 2019-08-05 12:15  月光宝盒造梦师  阅读(318)  评论(0编辑  收藏  举报