How to cycle through TR tags in TABLE

hi there,

I have the following table
<table id="mytable">
      <tr id="myHeader">
            <th">ID</th>
            <th">Value</th>
      </tr>
      <tr id="row_0">
            <td>value_0</td>
            <td>display_0</td>
      </tr>
      <tr id="row_1">
            <td>value_1</td>
            <td>display_1</td>
      </tr>
      <tr id="row_2">
            <td>value_2</td>
            <td>display_2</td>
      </tr>
      <tr id="row_3">
            <td>value_3</td>
            <td>display_3</td>
      </tr>
      <tr id="row_4">
            <td>value_4</td>
            <td>display_4</td>
      </tr>
      <tr id="row_5">
            <td>value_5</td>
            <td>display_5</td>
      </tr>
</table>

How with javascript can i cycle through the rows? I wish to apply a background style on some rows.

I have tried various methods which i wont post here to clutter. I prefer a solution which does not cycle through all controls on the page, rather, just the rows of this table if possible.

This is for an intranet which is IE only, so an IE solution is fine.

thanks!
LVL 1
ValimaiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
var tbl = document.getElementById("myTable");
var thead = tbl.firstChild;//IE implicitly adds thead element
var tr = thead.getElementsByTagName("tr");
for(var i=0, limit=tr.length; i < limit; ++i )
{
 alert(tr[i].id)
}
0
hieloCommented:
Not sure, but I believe this would have worked as well. Give them both a try:
var tbl = document.getElementById("myTable");
var tr = tbl.getElementsByTagName("tr");
for(var i=0, limit=tr.length; i < limit; ++i )
{
 alert(tr[i].id);
}

PS: change your id on your table to "myTable" uppercase "T" since that's what I used on the code
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ValimaiAuthor Commented:
bravo, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.