The getAttribute MethodAs its name implies, the getAttribute returns the value of an attribute. You can see the support for this method in Table 6.22. Table 6.22. The getAttribute Method
You pass this method the name of the attribute to get, and, optionally , the case argument, which, if true, makes the browser search for attributes in a case-sensitive way. Here's an example where I'm getting the value of a <FORM> element: (Listing 06-07.html on the web site)<HTML> <HEAD> <TITLE>Using the getAttribute Method</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function getAttr() { document.form1.text1.value = "The name of the form is " + document.form1.getAttribute("NAME") } // --> </SCRIPT> </HEAD> <BODY> <H1>Using the getAttribute Method</H1> <FORM NAME="form1"> <INPUT TYPE="TEXT" ID="text1" SIZE="50"></INPUT> <BR> <INPUT TYPE="BUTTON" ONCLICK="getAttr()" VALUE="Get Attribute"></INPUT> </FORM> </BODY> </HTML> You can see the results in Figure 6.5, where I'm retrieving the name of the form, form1. Figure 6.5. Getting an attribute's value.
|