Document: createProcessingInstruction() メソッド
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.
createProcessingInstruction()
は新しい処理命令ノードを生成して返します。
新しいノードは node.insertBefore
のように、あらゆることを成立させるために XML 文書に挿入されます。
構文
js
createProcessingInstruction(target, data)
引数
piNode
は結果のProcessingInstruction
ノードです。target
は処理命令の最初の部分 (つまり<?target … ?>
) を含む文字列です。data
は target の後に処理命令が伝えるすべての情報を含む文字列です。このデータはあなた次第ですが、?>
は処理命令を閉じるので含むことができません。
返値
なし (undefined
)。
例外
InvalidCharacterError
DOMException
-
以下の何れかが真になると例外が発生します。
例
js
const doc = new DOMParser().parseFromString("<foo />", "application/xml");
const pi = doc.createProcessingInstruction(
"xml-stylesheet",
'href="mycss.css"',
);
doc.insertBefore(pi, doc.firstChild);
console.log(new XMLSerializer().serializeToString(doc));
// 表示結果: <?xml-stylesheet href="mycss.css" type="text/css"?><foo/>
仕様書
Specification |
---|
DOM # ref-for-dom-document-createprocessinginstruction① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createProcessingInstruction |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.