How to use DOM Element removeAttributeNS in JavaScript

In this article I am going to explain about DOM Element removeAttribute() method in JavaScript
  • 1724

JavaScript DOM Element removeAttributeNS() Method

JavaScript removeAttributeNS() method use for remove attribute with specified tag name from specified namespace.

Syntax

element.removeAttributeNS(url,attribute)

Example

<html>

<head>

    <script type="text/javascript">

        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("http://www.dotnetheaven.com/NS", "name")[0];

 

        function check() {

            var y = x.hasAttributeNS("http://www.dotnetheaven.com/NS", "currency");

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

        };

 

        function remove() {

            x.removeAttributeNS("http://www.dotnetheaven.com/NS", "currency");

        };

    </script>

</head>

<body>

    <button onclick="check()">

        click me</button>

    <button onclick="remove()">

        Remove attribute</button>

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

        click button to check name element has currency attribute exist or not</p>

</body>

</html>

 

Output

 

Before click

 

 removeNS1.gif

 

After click

 

 removeNS2.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

© 2019 DotNetHeaven. All rights reserved.