Metodo removeAttributeNS() del DOM XML

Definizione e utilizzo

removeAttributeNS() Il metodo removeAttributeNS() rimuove l'attributo specificato dal nome e dallo spazio dei nomi.

Sintassi

elementNode.removeAttributeNS(ns,name)
Parametri Descrizione
ns Obbligatorio. Specifica lo spazio dei nomi dell'attributo da rimuovere.
name Obbligatorio. Specifica il nome dell'attributo da rimuovere.

Esempio

Il codice seguente carica "books_ns.xml" nel xmlDoc e rimuove l'attributo "lang" dal primo elemento <title>:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0];
    var ns = "https://www.codew3c.com/meishi/";
    document.getElementById("demo").innerHTML =
    "Attributo trovato: " + x.hasAttributeNS(ns, "lang");
    x.removeAttributeNS(ns, "lang");
    document.getElementById("demo").innerHTML +=
    "<br>Attributo trovato: " + x.hasAttributeNS(ns, "lang");
{}

Prova personalmente