Is “remove” a reserved keyword in Google Chrome?

后端 未结 3 964
死守一世寂寞
死守一世寂寞 2020-12-03 15:08

I have an interesting problem, and I think I got to the root of it, but I wanted to be sure. I have a link that calls a function called remove(). All browsers except Chrom

3条回答
  •  猫巷女王i
    2020-12-03 15:35

    I can't find any documentation on it, but DOM elements in Chrome have a native method remove that apparently removes them. In onclick, this actually refers to the element itself so it ends up calling this.remove() which removes the element. To get around this, you can just call window.remove() instead.

    http://jsfiddle.net/3YkZH/1/

    It would also be better to use standard event binding via addEventListener which does not have this problem when simply calling remove:

    http://jsfiddle.net/3YkZH/2/

提交回复
热议问题