?
Solved

count number of child tags

Posted on 2006-11-20
2
Medium Priority
?
2,462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 1000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
Suggested Courses

762 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