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

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 replaceChild() của giao diện Node thay thế một nút con hiện có bằng một nút khác.

Cú pháp

js
replaceChild(newChild, oldChild)

Tham số

newChild

Nút mới sẽ được chèn vào.

oldChild

Nút con hiện tại sẽ bị thay thế.

Giá trị trả về

Nút cũ đã bị thay thế.

Ví dụ

js
const parent = document.getElementById("parent");
const oldChild = document.getElementById("old");
const newChild = document.createElement("div");
parent.replaceChild(newChild, oldChild);

Xem thêm