JavaScript remove() doesn't work in IE

前端 未结 5 2021

I have the following code in JavaScript:

all_el_ul = document.getElementsByClassName(\'element_list\')[0];
div_list = all_el_ul.getElementsByTagName(\"div\")         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-05 04:43

    Try adding this to the top of your JavaScript file:

    if (!('remove' in Element.prototype)) {
      Element.prototype['remove'] = function () {
        if (this.parentNode) {
          this.parentNode.removeChild(this);
        }
      };
    }
    

    It is a small Element.remove() polyfill.

    Add that to your JS and [element].remove() should magically start working in IE.

提交回复
热议问题