ProcessingInstruction: target プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 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; 仕様書
| Specification |
|---|
| DOM> # dom-processinginstruction-target> |