25.94. Element.getAttribute( ): return the string value of a named attributeDOM Level 1 Core:25.94.1. SynopsisString getAttribute(String name); 25.94.1.1. Arguments
25.94.1.2. ReturnsThe value of the named attribute as a string. If the attribute is not defined, this method is supposed to return an empty string. Some implementations return null in this case, however. 25.94.2. DescriptiongetAttribute( ) returns the value of a named attribute of an element. Note that the HTMLElement object defines JavaScript properties that match each of the standard HTML attributes, so you need to use this method with HTML documents only if you are querying the value of nonstandard attributes. In XML documents, attribute values are not available directly as element properties and must be looked up by calling this method. For XML documents that use namespaces, use getAttributeNS( ). 25.94.3. ExampleThe following code illustrates two different ways of obtaining an attribute value for an HTML <img> element: // Get all images in the document var images = document.body.getElementsByTagName("img"); // Get the src attribute of the first one var src0 = images[0].getAttribute("src"); // Get the src attribute of the second simply by reading the property var src1 = images[1].src; 25.94.4. See AlsoElement.getAttributeNode( ), Element.getAttributeNS( ), Node |