JavaScript document.getElementsByTagNameNS() Method

You are Here:

JavaScript document.getElementsByTagNameNS() Method

The document.getElementsByTagNameNS() method returns a list of elements with the given tag name belonging to the given namespace.

Note: This method will search the entire document, including the root node.

Note: The XML file used in the example: student.xml.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var y, z, i, elem, text, xmlDoc, txt; var x = document.getElementById("point"); 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; } }; xhttp.open("GET", "/student.xml", true); xhttp.send(); </script> </body> </html>

Syntax

document.getElementsByTagNameNS(namespace, name)

Parameter Values

ValueTypeExplanation
namespaceRequiredSpecifies the namespace URI of elements to look for.
nameRequiredSpecifies the name of elements to look for.

Reminder

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