ProcessingInstruction: target property
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.
The read-only target
property of the ProcessingInstruction
interface
represent the application to which the ProcessingInstruction
is targeted.
For example:
html
<?xml version="1.0"?>
is a processing instruction whose target
is xml
.
Value
A string containing the name of the application.
Example
In an XML document
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 = `This processing instruction's target is: ${doc.firstChild.target}`;
In an HTML document
The processing instruction line will be considered, and represented, as a Comment
object.
html
<?xml version="1.0"?>
<pre></pre>
js
const node = document.querySelector("pre").previousSibling.previousSibling;
const result = `Node with the processing instruction: ${node.nodeName}: ${node.nodeValue}\n`;
document.querySelector("pre").textContent = result;
Specifications
Specification |
---|
DOM Standard # dom-processinginstruction-target |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
target |
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.
See also
- The DOM API