document.createProcessingInstruction(target, data) creates a ProcessingInstruction node — the DOM form of <?target data?> in XML (for example xml-stylesheet). You usually insert it into an XML document with insertBefore (MDN).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.createProcessingInstruction. Start with this line.
JavaScript
doc.createProcessingInstruction(target, data)
Call
What it does
doc.createProcessingInstruction(target, data)
Primary signature.
document.createProcessingInstruction(...)
Call with the arguments your case needs.
Built into the browser. Call createProcessingInstruction(...) on document — no import required.
Library declarations
JavaScript
doc.createProcessingInstruction(target, data)
Parameters
Parameter
Description
target
Required. Valid XML name (first part of <?…?>)
data
Required. Payload after the target — must not contain ?>
Return Value
Return Value
Description
*
ProcessingInstruction (not yet in the tree)
JavaScript Examples
Example 1 — Create xml-stylesheet and Serialize
MDN pattern: create a PI, insert it before the document element, serialize.
It creates a new ProcessingInstruction node from a target string and a data string (MDN). You usually insert it into an XML document — for example with insertBefore.
No. MDN marks Document.createProcessingInstruction() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A ProcessingInstruction node. Read pi.target and pi.data (or nodeValue / textContent for the data).
Serialized form is <?target data?>. MDN’s example builds an xml-stylesheet PI before the document element.
MDN: InvalidCharacterError if target is not a valid XML name, or if data contains the closing sequence ?>.
Processing instructions are an XML concept. MDN shows creating them on an XML Document from DOMParser (application/xml). Everyday HTML UIs rarely need them.