createProcessingInstruction() generates a new processing instruction node, and returns it.


piNode = document.createProcessingInstruction(target, data) 


  • piNode is a ProcessingInstruction node.
  • target refers to the first part of the processing instruction (i.e., <?target … >)
  • data is a string containing the data of the node.


Thrown if you try adding an invalid processing instruction target (it should be a valid XML name besides any case combination of the letters "xml"), or if the closing processing instruction sequence (?>) is added as part of the data.


var doc = new DOMParser().parseFromString('<xml></xml>', "application/xml")
var pi = doc.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');

doc.insertBefore(pi, doc.firstChild);

alert(new XMLSerializer().serializeToString(doc));
// Displays: <?xml-stylesheet href="mycss.css" type="text/css"?><xml/>


DOM 4: createProcessingInstruction

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Contributors to this page: mfuji09, Tigt, fscholz, teoli, Krinkle, kscarfone, Sheppy, dbruant, Zcorpan, Brettz9
Last updated by: mfuji09,