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 July 2015.

targetProcessingInstruction インターフェイスの読み取り専用プロパティで、 ProcessingInstruction が対象とするアプリケーションを表します。

例えば次のようなものです。

html
<?xml version="1.0"?>

この場合、処理命令の targetxml です。

アプリケーションの名前が入った文字列です。

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
target

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報