The tagName Property


The tagName Property

As we know, the tagName property holds the tag name of an elementfor example, a <P> element's tagName property will hold "P" . You can find the support for this property in Table 5.56.

Table 5.56. The tagName Property

Property

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

tagName

     

x

   

x

x

x

x

 

Read-only

 

Type: String

We've already see the tagName property at work; this example from Chapter 4 shows several different ways of accessing HTML elements:

(Listing 04-10.html on the web site)
 <HTML>      <HEAD>          <TITLE>              Accessing HTML Elements          </TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--             function getText()              {                  if(navigator.appName == "Netscape") {  alert("document.getElementsByName(\"text1\")[0].tagName= "   + document.getElementsByName("text1")[0].tagName)   alert("document.getElementsByTagName(\"P\")[0].tagName= "   + document.getElementsByTagName("P")[0].tagName)   }  if (navigator.appName == "Microsoft Internet Explorer") {  alert("document.all.text1.tagName = "   + document.all.text1.tagName)   alert("document.all[\"text1\"].tagName = "   + document.all["text1"].tagName)   alert("document.all.tags(\"P\").tagName = "   + document.all.tags("P")[0].tagName)   alert("document.getElementsByName(\"text1\")[0].tagName = "   + document.getElementsByName("text1")[0].tagName)   alert("document.getElementsByTagName(\"P\")[0].tagName = "   + document.getElementsByTagName("P")[0].tagName)  }              }              // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Accessing HTML Elements</H1>          <P NAME="text1" ID="text1">              Here's the text.          </P>          <FORM NAME="form1">              <INPUT TYPE="BUTTON" VALUE="Click Me!" ONCLICK="getText()">          </FORM>      </BODY>  </HTML> 


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