The firstChild and lastChild PropertiesThe firstChild and lastChild properties return the first and last child nodes of a specific node, or a value of null if there is no such child. You can see the support for these properties in Table 5.22. Table 5.22. The firstChild and lastChild Properties
Here's an example putting the firstChild and lastChild properties to workin this case, the code will report the names of the two children of a form using these properties: (Listing 05-13.html on the web site)<HTML> <HEAD> <TITLE> Using the firstChild and lastChild Properties </TITLE> </HEAD> <BODY> <H1>Using the firstChild and lastChild Properties</H1> <FORM NAME="form1"> <INPUT TYPE="BUTTON" NAME="button1" VALUE="Click Me!" ONCLICK="getText()"> <INPUT TYPE="TEXT" NAME="text1"></FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- document.write("document.all.form1.firstChild.name = " + document.all.form1.firstChild.name + "<BR>") document.write("document.all.form1.lastChild.name = " + document.all.form1.lastChild.name + "<BR>") // --> </SCRIPT> </BODY> </HTML> You can see the results in Figure 5.10. Figure 5.10. Using the firstChild and lastChild properties.
|