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.

Syntax

element.getElementByTagNameNS(tagname name)

Example

<html>

<head>

    <script type="text/javascript">

        function myfun() {

            var http;

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

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

 

            Xm.open("GET", "myfile.xml", false);

            Xm.send();

            var xmlDoc = Xm.responseXML;

            var x = xmlDoc.getElementsByTagNameNS("https://dotnetheaven.com/NS", "book")[0];

            var y = x.getElementsByTagNameNS("https://dotnetheaven.com/NS", "cost")[0];

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

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

        };

    </script>

</head>

<body>

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

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

    <button onclick="myfun()">

        click me</button>

</body>

</html>

 

Output

 

Before click

 

 url1.gif

 

After click

 

 url2.gif

 

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
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.