lakshmipcb
02-14-2005, 05:34 PM
I was wondering is there any simple method to travers through from one tag to its childhren nodes.
For example
<div>
child nodes ?
</div>
For example
<div>
child nodes ?
</div>
|
||||
traversing from <div> Tag to there chid nodeslakshmipcb 02-14-2005, 05:34 PM I was wondering is there any simple method to travers through from one tag to its childhren nodes. For example <div> child nodes ? </div> Kor 02-15-2005, 08:09 AM Probably something like this: var root = element_reference_as_Node; var oChild=root.firstChild; while(oChild!=null){ if(oChild.innerHTML!=null){ alert(oChild.innerHTML) } oChild=oChild.nextSibling; } For instance: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script language="JavaScript" type="text/JavaScript"> function bla(){ var root = document.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0]; var oChild=root.firstChild; while(oChild!=null){ if(oChild.innerHTML!=null){//avoids the Moz traversing through empty textNodes alert(oChild.innerHTML) } oChild=oChild.nextSibling; } } onload=bla; </script> </head> <body> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tbody> <tr> <td>qqqqqqqq</td> </tr> <tr> <td>wwwwwwww</td> </tr> <tr> <td>eeee</td> </tr> <tr> <td>rrrrrr</td> </tr> <tr> <td>tttttt</td> </tr> </tbody> </table> </body> </html> |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum