1

I have this line of code, but it seems internet explorer does not recognize the 'remove' function.

this.options[this.selectedIndex].remove();

error says 'Object does not support remove function', any idea how to do this in IE?

note: this=select element and it works both in Firefox and Chrome

xird
  • 775
  • 1
  • 8
  • 16

2 Answers2

1

IE doesn't support .remove(), you need to use element.parentNode.removeChild(element) or a polyfill like below. See:

https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

  // from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
    (function (arr) {
        arr.forEach(function (item) {
            item.remove = item.remove || function () {
                this.parentNode.removeChild(this);
            };
        });
    })([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
SpliFF
  • 38,186
  • 16
  • 91
  • 120
0

IE doesn't support remove() in Javascript. Only in jQuery.

If you want to use remove() in Javascript put this following code above your code calling remove method :

// Create remove function if not exist
  if (!('remove' in Element.prototype)) {
   Element.prototype.remove = function() {
    if (this.parentNode) {
        this.parentNode.removeChild(this);
    }
 };
}
// Call remove() according to your need
myVar.remove();

More info on removeChild() : https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

Happy coding ! :)