Solved

count number of child tags

Posted on 2006-11-20
2
2,455 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now