okay
okay

Reputation: 173

getting all td in a variable

how do i get all the first td in a variable of following table

<table cellpadding="0" cellspacing="0" border="0" width="100%" class="myTable">
         <tr >
        <td>785.1 </td>
        <td>do not pick me</td>
      </tr>
      <tr >
        <td>427.31</td>
        <td>do not pick me</td>
      </tr>
      <tr >
        <td>780.2</td>
        <td>do not pick me</td>
      </tr>
      <tr>
</table>

Upvotes: 1

Views: 716

Answers (4)

kbbagal
kbbagal

Reputation: 49

You can select first of each for table you gave in question as follows ,

    var firstTDS    =   $(".myTable tr td:first-child");

This is a list of first of each , you can process them by traversing firstTDS . For example to change background color of first of each , you can do ,

   for(var i in firstTDS)
   {
     $(firstTDS[i]).css('background-color','red');
   }

That's it .

Upvotes: 0

rahul
rahul

Reputation: 7663

you can do it like this

var Firsttds = $(".myTable tr td:first-child");
alert(Firsttds.length)​;​

Upvotes: 0

Flater
Flater

Reputation: 13783

You mean the first TD element of each TR element within the table?

var fields = $("#myTable>tr>td:first-child");

Upvotes: 0

VisioN
VisioN

Reputation: 145398

Do you mean something like that?

var tds = $(".myTable td:first-child");

DEMO: http://jsfiddle.net/S2N5n/

Upvotes: 2

Related Questions