The getAttribute Method


The getAttribute Method

As 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

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

getAttribute( attribute , [, case ])

     

x

   

x

x

x

x

 

Returns: Attribute value

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.

graphics/06fig05.gif



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net