How to use DOM Element removeAttributeNS in JavaScript

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

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

 

        function check() {

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

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

        };

 

        function remove() {

            x.removeAttributeNS("https://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

© 2020 DotNetHeaven. All rights reserved.