The tagName PropertyAs 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
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> |