How to use DOM Element SetAttributeNodeNs in JavaScript

In this article I am going to explain about DOM element setAttributeNodeNS() method in JavaScript.
  • 1656

JavaScript DOM Element setAttributeNodeNS() Method

JavaScript setAttributeNodeNS() method use for set specified attribute node to an element in specified namespace. If attribute already exists on element then then its will replaced it.






    <script type="text/javascript">

        var http;

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

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

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


        var xmlDoc = yy.responseXML;

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


        function check() {

            var y = x.hasAttributeNS("", "country");

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



        function Add() {

            var mm = xmlDoc.createAttributeNS("", "country");

            mm.value = "India";






    <button onclick="check()">

        check it</button>

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

        click button to check country attribute exists or not</h1>


        click this button to add country attribute</p>

    <button onclick="Add()">

        Add attribute</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.