<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>demo</title> </head> <body> <div class="tempDiv"></div> <div class="tempDiv"></div> <div class="tempDiv"></div> <div class="tempDiv"></div> <div class="tempDiv"></div> <div class="tempDiv"></div> </body> </html>
function removeChild() { var child= document.getElementsByClassName("tempDiv"); child.removeNode = []; if (child.length != undefined) { var len = child.length; for (var i = 0; i < len; i++) { child.removeNode.push({ parent: child[i].parentNode, inner: child[i].outerHTML, next: child[i].nextSibling }); } for (var i = 0; i < len; i++){ child[0].parentNode.removeChild(child[0]); } } else { child.removeNode.push({ parent: child.parentNode, inner: child.outerHTML, next: child.nextSibling }); child.parentNode.removeChild(child); } }
原文地址:https://www.cnblogs.com/xxySsm/p/11758759.html
时间: 2024-10-04 01:57:45