Metoda HTML DOM removeAttributeNode()
❮ Obiekt elementuPrzykład
Usuń węzeł atrybutu klasy z elementu <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>
Definicja i użycie
Metoda removeAttributeNode() usuwa określony atrybut z elementu i zwraca usunięty atrybut jako obiekt Attr Node .
Różnica między tą metodą a metodą removeAttribute() polega na tym, że metoda removeAttribute() usuwa atrybut o określonej nazwie , podczas gdy ta metoda usuwa określony obiekt Attr . Wynik będzie taki sam. Ponadto metoda removeAttribute() nie zwraca wartości , podczas gdy ta metoda zwraca usunięty atrybut jako obiekt Attr.
Wskazówka: Użyj metody getAttributeNode() , aby zwrócić węzeł atrybutu elementu.
Wskazówka: Użyj metody setAttributeNode() , aby dodać węzeł atrybutu do elementu.
Obsługa przeglądarki
Method | |||||
---|---|---|---|---|---|
removeAttributeNode() | Yes | Yes | Yes | Yes | Yes |
Składnia
element.removeAttributeNode(attributenode)
Wartości parametrów
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
Szczegóły techniczne
Wartość zwrotu: | Obiekt Attr, reprezentujący usunięty węzeł atrybutu |
---|---|
Wersja DOM | Obiekt elementu podstawowego poziomu 1 |
Więcej przykładów
Przykład
Usuń węzeł atrybutu href z elementu <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>
Powiązane strony
Samouczek HTML: atrybuty HTML
Dokumentacja HTML DOM: obiekt atrybutu HTML DOM
Dokumentacja HTML DOM: metoda removeAttribute()
Dokumentacja HTML DOM: metoda getAttributeNode()
Dokumentacja HTML DOM: metoda setAttributeNode()
❮ Obiekt elementu