METHOD:  Element::removeAttribute

Element.removeAttribute(name)

The removeAttribute method is used to remove an attribute of the specified name from the element. If the removed attribute has a default value defined in a DTD, it is immediately replaced by it.

In the following example using the 'albums.xml' file the 'category' attribute is removed from the first 'Album' element. The code then displays the names of the remaining attributes.

XML:
<Albums>
   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   </Album>
   <Album ref="CD720" category="Pop">
      <title>Come On Over</title>
      <artist>Shania Twain</artist>
   </Album>
   <Album ref="CD024" category="Country">
      <title>Red Dirt Girl</title>
      <artist>Emmylou Harris</artist>
   </Album>
</Albums>

Code (JavaScript):
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("albums.xml");

elem = xml_doc.documentElement.firstChild;
elem.removeAttribute("category");
atts = elem.attributes;
n_atts = atts.length;
for (i = 0; i < n_atts; i++)
   document.write(atts[i].name + "<br>");

Output:
ref



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information