You are here: Reference > JavaScript > client-side > HTML DOM > methods > getElementsByTagNameNS

getElementsByTagNameNS method

Browser support:
Returns a NodeList collection that contains all descendant elements of the current element with the specified namespace URI and local name.
Note: Internet Explorer supports the getElementsByTagNameNS method from version 9, but only for HTML documents, not for XML documents.
The getElementsByTagNameNS method is case-sensitive for both the namespace URI and the local name.
The returned NodeList collection is a live collection, which means that the modification of the document affects the collection. If you need an example that illustrates the meaning of live collections, please see the page for the getElementsByTagName method.


object.getElementsByTagNameNS (namespaceURI, tagName);
You can find the related objects in the Supported by objects section below.


Required. String that specifies the namespace URI of the elements to look for.
Required. String that specifies the local name of the elements to look for.

Return value:

Returns a NodeList collection filled with the matching elements. The elements in the returned collection are in source order.

Example HTML code 1:

This example illustrates the use of the getElementsByTagNameNS method:
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript">
        var httpRequest = null;
        function SendRequest () {
            if (!httpRequest) {
                httpRequest = CreateHTTPRequestObject ();   // defined in ajax.js
            if (httpRequest) {          
                    // The requested file must be in the same domain that the page is served from.
                var url = "ns.xml";
       ("GET", url, true);    // async
                httpRequest.onreadystatechange = OnStateChange;
                httpRequest.send (null);

        function OnStateChange () {
            if (httpRequest.readyState == 0 || httpRequest.readyState == 4) {
                if (IsRequestSuccessful (httpRequest)) {    // defined in ajax.js
                    Test_GetElementsByTagNameNS ();
                else {
                    alert ("Operation failed.");

        function Test_GetElementsByTagNameNS () {
            var xmlDoc = ParseHTTPResponse (httpRequest);   // defined in ajax.js
            if (!xmlDoc)

            if (xmlDoc.getElementsByTagNameNS) {
                var titleTags = xmlDoc.getElementsByTagNameNS ("", "title");
                alert ("Count of title tags: " + titleTags.length);
                if (titleTags.length > 0) {
                    alert ("The local name of the first title tag: " + titleTags[0].localName);
                    alert ("The namespaceURI of the first title tag: " + titleTags[0].namespaceURI);
            else {
                alert ("Your browser doesn't support the getElementsByTagNameNS method.");

    <button onclick="SendRequest ()">Get the 'title' tags with the namespace</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content