.remove() not working in Internet Explorer [duplicate]

对着背影说爱祢 提交于 2019-12-12 03:18:05

问题


This code works very well in Google Chrome, but wont work in Internet Explorer:

document.getElementsByClassName('info')[i].remove();

Is there some other method to do the same thing or can I make .remove() work in Internet Explorer?


回答1:


remove is not supported by ie

You would have to get the parent and call removeChild

var node = document.getElementsByClassName('info')[i];
node.parentNode.removeChild(node);

Also since you have jQuery tagged you could just do

jQuery(".info").eq(i).remove()

as jQuery does cross browser checks and uses the correct methods



来源:https://stackoverflow.com/questions/32670780/remove-not-working-in-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!