ใช้ removeChild() ลบอีเลเมนต์ลูกออกจากอีเลเมนต์พาเรนต์
ไวยากรณ์
parent.removeChild(childElement);
ตัวอย่าง
<html> <body>
<div id="new">
<p id="p1">Tutorix</p>
<p id="p2">Tutorialspoint</p>
</div>
<script>
var parent = document.getElementById("new");
var child = document.getElementById("p1");
parent.removeChild(child);
</script> </body> </html>
ผลลัพธ์
Tutorialspoint
อีเลเมนต์ p1 ถูกลบ เหลือ p2 อยู่ใน div