Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project











METHOD:  Element::getAttribute

Element.getAttribute(name)

The getAttribute method returns a string containing the value of the specified attribute. If the named attribute does not have a specified or default value, this method returns null.

The following example uses the 'states.xml' file. Firstly a NodeList is created of all the 'State' elements, and then the code iterates through them getting the value of the 'ref' attribute of each.

XML:
<States>
   <State ref="FL" const="27">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA" const="29">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

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

states = xml_doc.getElementsByTagName("State");
n_states = states.length;
for (i = 0; i < n_states; i++)
{
   state = states.item(i);
   attr = state.getAttribute("ref");
   document.write(attr + "<br>");
}

Output:
FL
IA



 


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