XML DOM removeAttribute() 方法

定義和用法
removeAttribute() 方法刪除指定的屬性。
如果屬性的默認值是在 DTD 中定義,那麼新屬性出現時會帶有該默認值。
語法
elementNode.removeAttribute(name)
參數 | 描述 |
---|---|
name | 必需。規定要刪除的屬性。 |
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並刪除所有 <book> 元素的 "category" 屬性:
實例
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
document.write(x[0].getAttribute('category'));
document.write("<br>");
x[0].removeAttribute('category');
document.write(x[0].getAttribute('category'));
