Solved

count number of child tags

Posted on 2006-11-20
2
2,457 Views
Last Modified: 2008-01-09
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
Comment
Question by:freezegravity
2 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 250 total points
ID: 17982605
<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
 

Author Comment

by:freezegravity
ID: 17982789
Works great!

Thanks a bunch!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question