JavaScript document.createProcessingInstruction() Method

You are Here:

JavaScript document.createProcessingInstruction() Method

The document.createProcessingInstruction() method generates a new processing instruction node and returns it.


The XML file used in the example: person.xml.

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Display XML with CSS property</p> <p>Click the button to create processing instruction of xml</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); function myFunction() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function(){ if(this.readyState == 4 && this.status == 200){ var xmlDoc=xhttp.responseXML; var pi = xmlDoc.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'); xmlDoc.insertBefore(pi, xmlDoc.firstChild); var xmlText = new XMLSerializer().serializeToString(xmlDoc); var xmlTextNode = document.createTextNode(xmlText); x.appendChild(xmlTextNode); } };"GET", "/person.xml", true); xhttp.send(); } </script> </body> </html>


document.createProcessingInstruction(target, data)

Parameter Values

targetRequiredA string containing the first part of the processing instruction.
dataRequiredA string containing the information of the processing instruction.


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author