Inside JavaScript

The tags Method

In the Internet Explorer, the tags method retrieves a collection of objects that have the specified HTML tag name . You can see the support for this method in Table 6.53.

Table 6.53. The tags Method

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

tags( tag )

           

x

x

x

x

 

Returns: Element object array

This method is part of collections like the all and forms collections. We've already put the tags method to work in Chapter 4:

(Listing 04-11.html on the web site)

<HTML> <HEAD> <TITLE> Accessing HTML Elements </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function getText() { if(navigator.appName == "Netscape") { alert("document.form1.text1.value = " + document.form1.text1.value) alert("document.forms[0].text1.value = " + document.forms[0].text1.value) alert("document.getElementsByName(\"text1\")[0].value = " + document.getElementsByName("text1")[0].value) alert("document.getElementsByTagName(\"INPUT\")[0].value = " + document.getElementsByTagName("INPUT")[0].value) } if (navigator.appName == "Microsoft Internet Explorer") { alert("document.form1.text1.value = " + document.form1.text1.value) alert("document.forms[0].text1.value = " + document.forms[0].text1.value) alert("document.all.text1.value = " + document.all.text1.value) alert("document.all[\"text1\"].value = " + document.all["text1"].value) alert("document.all.tags(\"INPUT\")[0].value = " + document.all.tags("INPUT")[0].value) alert("document.getElementsByName(\"text1\")[0].value = " + document.getElementsByName("text1")[0].value) alert("document.getElementsByTagName(\"INPUT\")[0].value = " + document.getElementsByTagName("INPUT")[0].value) } } // --> </SCRIPT> </HEAD> <BODY> <H1>Accessing HTML Elements</H1> <FORM NAME="form1"> <INPUT TYPE="TEXT" NAME="text1" ID="text1"> <INPUT TYPE="BUTTON" VALUE="Click Me!" ONCLICK="getText()"> </FORM> </BODY> </HTML>

Категории