DocumentType: phương thức replaceWith()

Baseline Widely available

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

Phương thức DocumentType.replaceWith() thay thế kiểu tài liệu bằng một tập hợp các nút đã cho.

Cú pháp

js
replaceWith(node1)
replaceWith(node1, node2)
replaceWith(node1, node2, /* …, */ nodeN)

Tham số

node1, ..., nodeN

Một tập hợp các nút dùng để thay thế DocumentType.

Giá trị trả về

Không có (undefined).

Ngoại lệ

HierarchyRequestError DOMException

Được ném ra khi nút không thể được chèn tại điểm đã chỉ định trong cây phân cấp.

Ví dụ

Sử dụng replaceWith()

js
let svgDt = document.implementation.createDocumentType(
  "svg:svg",
  "-//W3C//DTD SVG 1.1//EN",
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd",
);

document.doctype.replaceWith(svgDt);

Thông số kỹ thuật

Specification
DOM
# ref-for-dom-childnode-replacewith①

Tương thích trình duyệt

Xem thêm