How to remove all elements of a certain class from the DOM?

后端 未结 4 789
有刺的猬
有刺的猬 2020-11-29 06:34



        
4条回答
  •  长情又很酷
    2020-11-29 07:05

    Afaik only a parent can remove a child in native JS. So you would first have to get that elements parent, then use the parent to remove the element. Try this:

    var parent = paras[i].parentNode;
    parent.removeChild(paras[i]);
    

提交回复
热议问题