How to remove the parent element using plain Javascript

前端 未结 9 920
一生所求
一生所求 2020-12-03 04:37

How do I remove the parent element and all the respective nodes using plain JavaScript? I\'m not using jQuery or any other library. In other words, I have an element and whe

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 04:44

    node.parentNode.parentNode.removeChild(node.parentNode)
    

    Edit: You need to to delete parent of parent, so add one more .parentNode

    node.parentNode.parentNode.parentNode.removeChild(node.parentNode.parentNode)
    

提交回复
热议问题