• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2465
  • Last Modified:

count number of child tags

Hello experts:

Is there an easy way to count the number of child tags an html tag has?

For example, I want to know the number of columns for this row in a table (in this case, it is three, but I want to write a for loop that goes through each of the tds in a table where I don't know the column amount):

<tr id="some_row">
   <td>value 1</td>
   <td>value 2</td>
   <td align="center">value 3</td>
</tr>

Thanks in advance for your help
0
freezegravity
Asked:
freezegravity
1 Solution
 
callrsCommented:
<table>
<tr id="some_row">
   <td>value 1</td>
   <td>value 2</td>
   <td align="center">value 3</td>
</tr>
</table>
<script type="text/javascript">
var TR=document.getElementById("some_row")
var TD=TR.getElementsByTagName("td")
alert(TD.length)
</script>
0
 
freezegravityAuthor Commented:
Works great!

Thanks a bunch!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now