JavaScript document.createElementNS() Method

You are Here:

JavaScript document.createElementNS() Method

The document.createElementNS() method creates an element with the specified namespace URI and qualified name.

Tips: To create an element without specifying a namespace URI, use the createElement() method.

Note: The XML file used in this example is student.xml.


HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); var y, z, i, elem, text, xmlDoc, txt; var txt = ""; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function(){ if(this.readyState == 4 && this.status == 200){ xmlDoc = xhttp.responseXML; y = xmlDoc.getElementsByTagName("name"); for(i = 0; i < y.length; i++) { elem = xmlDoc.createElementNS("anyString", "age"); text = xmlDoc.createTextNode("18"); elem.appendChild(text); y[i].appendChild(elem); } z = xmlDoc.getElementsByTagNameNS("anyString","age"); for(i = 0; i < y.length; i++){ txt += "Name: " +y[i].childNodes[0].nodeValue ; txt += " Age: " +z[i].childNodes[0].nodeValue ; txt += " NS: " + z[i].namespaceURI +"<br>"; } x.innerHTML = txt; } };"GET", "/student.xml", true); xhttp.send(); </script> </body> </html>


document.createElementNS(namespaceURI, name)

Parameter Values

namespaceURIRequiredA string that specifies the namespace URI to associate with the element.
nameRequiredA string that specifies the type of element to be created.

Return Values

ObjectReturns the new element.


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