DOM - Metodo oggetto elemento - removeAttributeNS

Il metodo removeAttributeNS rimuove un attributo in base al nome locale e all'URI dello spazio dei nomi.

Sintassi

Di seguito è riportata la sintassi per l'utilizzo del metodo removeAttributeNS .

elementObj.removeAttributeNS(namespace,attrName)

S.No. Parametro e descrizione
1

namespace

È una stringa che specifica lo spazio dei nomi dell'attributo.

2

attrName

È una stringa che denomina l'attributo da rimuovere dal nodo corrente.

Restituisce un nodo Attr per l'attributo specificato.

Esempio

I contenuti di node_ns.xml sono i seguenti:

<?xml version = "1.0"?>
<Company>
   <Employee xmlns:e = "http://www.tutorials.com/technical/" category = "technical">
      <e:FirstName e:lang = "en">Tanmay</e:FirstName>
      <e:LastName>Patil</e:LastName>
      <e:ContactNo>1234567890</e:ContactNo>
      <e:Email>[email protected]</e:Email>
   </Employee>
   
   <Employee xmlns:n = "http://www.tutorials.com/non-technical/" category = "non-technical">
      <n:FirstName n:lang = "en">Taniya</n:FirstName>
      <n:LastName>Mishra</n:LastName>
      <n:ContactNo>1234667898</n:ContactNo>
      <n:Email>[email protected]</n:Email>
   </Employee>
</Company>

L'esempio seguente dimostra l'utilizzo del metodo removeAttributeNS :

<!DOCTYPE html>
<html>
   <head>
      <script>
         function loadXMLDoc(filename) {
            if (window.XMLHttpRequest) {
               xhttp = new XMLHttpRequest();
            } else // code for IE5 and IE6 {
               xhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xhttp.open("GET",filename,false);
            xhttp.send();
            return xhttp.responseXML;
         }
      </script>
   </head>
   <body>
      <script>
         xmlDoc = loadXMLDoc("/dom/node_ns.xml");
         x = xmlDoc.getElementsByTagName("FirstName")[0];
         ns = "http://www.tutorials.com/technical/";
         document.write("Before removing the attributeNS: ");
         document.write(x.getAttributeNS(ns,"lang"));
         x.removeAttributeNS(ns,"lang");
         document.write("<br>After removing the attributeNS: ");
         document.write(x.getAttributeNS(ns,"lang"));
      </script>
   </body>
</html>

Esecuzione

Salva questo file come elementattribute_removeAttributeNS.htm nel percorso del server (questo file e node_ns.xml dovrebbero trovarsi sullo stesso percorso nel tuo server). Otterremo l'output come mostrato di seguito -

Before removing the attributeNS: en
After removing the attributeNS: null