ProcessingInstruction: target プロパティ
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
target は ProcessingInstruction インターフェイスの読み取り専用プロパティで、 ProcessingInstruction が対象とするアプリケーションを表します。
例えば次のようなものです。
html
<?xml version="1.0"?>
この場合、処理命令の target は xml です。
値
アプリケーションの名前が入った文字列です。
例
>XML 文書内で
js
let parser = new DOMParser();
const doc = parser.parseFromString(
'<?xml version="1.0"?><test/>',
"application/xml",
);
const pi = doc.createProcessingInstruction(
"xml-stylesheet",
'href="mycss.css" type="text/css"',
);
doc.insertBefore(pi, doc.firstChild);
const output = document.querySelector("output");
output.textContent = `この処理命令のターゲット: ${doc.firstChild.target}`;
HTML 文書内で
処理命令の行は Comment オブジェクトと見なされ、表現されます。
html
<?xml version="1.0"?>
<pre></pre>
js
const node = document.querySelector("pre").previousSibling.previousSibling;
const result = `この処理命令のノード: ${node.nodeName}: ${node.nodeValue}\n`;
document.querySelector("pre").textContent = result;
仕様書
| 仕様書 |
|---|
| DOM> # dom-processinginstruction-target> |