How to use DOM Element GetElementByTagNameNS in JavaScript

In this article I am going to explain about DOM Element getElementByTagNameNS() method in JavaScript.
  • 1740

JavaScript DOM Element getElementByTagNameNS() Method

JavaScript getElementByTagNameNS() method use for get number of child element with specified by tag name and specified namespace as a node List object.


element.getElementByTagNameNS(tagname name)




    <script type="text/javascript">

        function myfun() {

            var http;

            if (window.XMLHttpRequest) { Xm = new XMLHttpRequest(); }

            else { Xm = new ActiveXObject("Microsoft.XMLHTTP"); }


  "GET", "myfile.xml", false);


            var xmlDoc = Xm.responseXML;

            var x = xmlDoc.getElementsByTagNameNS("", "book")[0];

            var y = x.getElementsByTagNameNS("", "cost")[0];

            var z = y.childNodes[0].nodeValue;

            document.getElementById("tst").innerHTML = z;





    <p id="tst" style="color: Blue">

        click button for get value of element with specefied url</p>

    <button onclick="myfun()">

        click me</button>






Before click




After click




You may also want to read these related articles: here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.