Node: phương thức removeChild()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phương thức removeChild() của giao diện Node xóa một nút con khỏi nút hiện tại.

Cú pháp

js
removeChild(child)

Tham số

child

Nút con cần xóa.

Giá trị trả về

Nút đã bị xóa.

Ngoại lệ

NotFoundError DOMException

Được ném ra nếu child không phải là nút con của nút hiện tại.

Ví dụ

js
const node = document.getElementById("box");
while (node.firstChild) {
  node.removeChild(node.firstChild);
}

Xem thêm