Alan Coromano
Alan Coromano

Reputation: 26008

Selecting rows in a table and replacing them with the new data

I have a table with headers:

<table id="my-table">
    <thead>
        <th>header1</th>
        <th>header2</th>  
        <th>header3</th>  
    </thead>
    <tbody>
      <tr>
         <td>data1</td>
         <td>data2</td>
         <td>data3</td>
      </tr>
    </tbody>
</table>

How do I select only rows and replace them with the new data using jQuery? Only rows and not headers.

Upvotes: 0

Views: 102

Answers (4)

Amrendra
Amrendra

Reputation: 2077

$('tr').not('thead tr').addClass('selected').

Upvotes: 0

allenhwkim
allenhwkim

Reputation: 27738

It seems obvious, I would try this

$("#my-table tbody tr")

Or this

$("#my-table tr:has(td)")

Upvotes: 1

bipen
bipen

Reputation: 36531

try this

 $('#my-table tbody tr td').each(function(){//to select all rows in the table with id my-table
   $(this).text('test');
});

Upvotes: 1

Ravi Y
Ravi Y

Reputation: 4376

You could use the context of the jquery selector as well...

$("tr", "#my-table tbody").each(function (i, item) {
    $("td", this).each(function () {
        // do something with the td.
    });
});

Upvotes: 1

Related Questions