Metodo HTML DOM removeAttributeNode()
❮ L'oggetto elementoEsempio
Rimuovere il nodo dell'attributo di classe da un elemento <h1>:
var elmnt = document.getElementsByTagName("H1")[0]; // Get the first <h1> element in the document
var attr = elmnt.getAttributeNode("class"); // Get the class attribute node from <h1>
elmnt.removeAttributeNode(attr); // Remove the class attribute node from <h1>
Definizione e utilizzo
Il metodo removeAttributeNode() rimuove l'attributo specificato da un elemento e restituisce l'attributo rimosso come oggetto Attr Node .
La differenza tra questo metodo e il metodo removeAttribute() è che il metodo removeAttribute() rimuove l'attributo con il nome specificato , mentre questo metodo rimuove l' oggetto Attr specificato . Il risultato sarà lo stesso. Inoltre, il metodo removeAttribute() non ha un valore restituito , mentre questo metodo restituisce l'attributo rimosso, come un oggetto Attr.
Suggerimento: utilizzare il metodo getAttributeNode() per restituire un nodo attributo di un elemento.
Suggerimento: utilizza il metodo setAttributeNode() per aggiungere un nodo attributo a un elemento.
Supporto browser
Method | |||||
---|---|---|---|---|---|
removeAttributeNode() | Yes | Yes | Yes | Yes | Yes |
Sintassi
element.removeAttributeNode(attributenode)
Valori dei parametri
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
Dettagli tecnici
Valore di ritorno: | Un oggetto Attr, che rappresenta il nodo dell'attributo rimosso |
---|---|
Versione DOM | Oggetto elemento di livello 1 di base |
Altri esempi
Esempio
Rimuovi il nodo dell'attributo href da un elemento <a>:
var elmnt = document.getElementById("myAnchor"); // Get the <a> element with id="myAnchor"
var attr = elmnt.getAttributeNode("href"); // Get the href attribute node from <a>
elmnt.removeAttributeNode(attr); // Remove the href attribute node from <a>
Pagine correlate
Esercitazione HTML: attributi HTML
Riferimento HTML DOM: l'oggetto attributo HTML DOM
Riferimento HTML DOM: metodo removeAttribute()
Riferimento HTML DOM: metodo getAttributeNode()
Riferimento HTML DOM: metodo setAttributeNode()
❮ L'oggetto elemento