Home > Article > Web Front-end > How to delete the parent node of the current element in javascript
Javascript method to delete parent node: 1. Find the parent node and grandfather node through the parentNode attribute; 2. Use the removeChild() function to delete the parent node, the syntax is "grandfather node.removeChild (parent node)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript deletes the parent node of the current element
Find the parent node through parentNode and then use removeChild to delete it. Just to delete the parent node, you need to find one more layer, that is, use grandpa to delete the father.
//删除方法 var deleteNode = function (my) { //先找到当前节点的父亲 var parentNode = my.parentNode; //找祖父节 var reprent = parentNode.parentNode; reprent.removeChild(parentNode); }
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to delete the parent node of the current element in javascript. For more information, please follow other related articles on the PHP Chinese website!