XML DOM removeAttributeNS() Method
Definition and Usage
The removeAttributeNS() method deletes the attribute specified by the namespace and name.
Syntax:
elementNode.removeAttributeNS(ns, name)
Parameters | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to be removed. |
name | Required. Specifies the name of the attribute to be removed. |
Example
In all examples, we will use the XML file books_ns.xml, and JavaScript function loadXMLDoc().
The following code snippet removes the "lang" attribute from the first <title> element in "books_ns.xml":
xmlDoc=loadXMLDoc("books_ns.xml"); x=xmlDoc.getElementsByTagName("title")[0]; ns="http://www.codew3c.com/children/"; document.write("Attribute Found: "); document.write(x.hasAttributeNS(ns,"lang")
; x.removeAttributeNS(ns,"lang"); document.write("<br />Attribute Found: "); document.write(x.hasAttributeNS(ns,"lang")
;
Output:
Attribute Found: true Attribute Found: false