このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

DocumentType: replaceWith() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2018年4月⁩.

DocumentType.replaceWith() メソッドは、文書型宣言を指定されたノードで置き換えます。

構文

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

引数

node1, …, nodeN

この DocumentType を置き換える一連のノードです。

返値

なし (undefined)。

例外

HierarchyRequestError DOMException

ノードが階層内の指定された位置に挿入できない場合に発生します。

replaceWith() の使用

js
let svg_dt = 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(svg_dt);

仕様書

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

ブラウザーの互換性

関連情報