The canHaveChildren Property


The canHaveChildren Property

When you're constructing your own web pages in JavaScript (using Dynamic HTML or W3C DOM methods ), it can be useful to see whether you're dealing with an element that can contain children or not (for example, <BR> elements cannot). You can see the support for this property in Table 5.9.

Table 5.9. The canHaveChildren Property

Property

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

canHaveChildren

           

x

x

x

 
 

Read-only

 

Type: Boolean

Here's an examplethis code loops over all elements in a web page and colors them green if they can have children:

(Listing 05-04.html on the web site)
 <HTML>      <HEAD>          <TITLE>Using the canHaveChildren Property</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  for (var loopIndex =0; loopIndex <document.all.length; loopIndex++){   if (document.all[loopIndex].canHaveChildren){   document.all[loopIndex].style.color = "green"  }              }              // -->          </SCRIPT>      </HEAD>      <BODY>          <H1 NAME="header">Using the canHaveChildren Property</H1>          <P NAME="p1">Here's a paragraph.</P>          <DIV NAME="div1">Here's a DIV.</DIV>      </BODY>  </HTML> 

You can see the results in Figure 5.3 in glorious black and whitealthough you can't tell, all the text in this figure is green. Give this one a tryload it into the Internet Explorer (this property isn't supported in the Netscape Navigator) yourself.

Figure 5.3. Using the canHaveChildren property.

graphics/05fig03.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