The attributes PropertyThe attributes property is a very useful one; it returns a collectionthat is, an arrayof the attributes of an element. You can see the support for the attributes property in Table 5.6. Table 5.6. The attributes Property
This property returns an array of attribute objects; you can see the properties of attribute objects in Table 5.7. Table 5.7. The attribute Object Properties
Here's an example; in this case, I'll take a look at the value of the onclick attribute's value in a button element: (Listing 05-03.html on the web site)<HTML> <HEAD> <TITLE>Using the attributes Property</TITLE> </HEAD> <BODY> <H1>Using the attributes Property</H1> <FORM NAME="form1"> <INPUT TYPE="BUTTON" ID="button1" ONCLICK="alert('Hello!')" VALUE="Click Me!"> <INPUT TYPE="TEXT" ID="text1" VALUE="Click Me!"> </FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- document.write(document.form1.button1.attributes["onclick"].name + " = " + document.form1.button1.attributes["onclick"].value) // --> </SCRIPT> </BODY> </HTML> You can see the results in Figure 5.2. Figure 5.2. Looking at an attribute in the Netscape Navigator.
|