Amrinder Singh
Amrinder Singh

Reputation: 5492

How to replace content of a td having certain text in a table using Jquery?

I want to replace content of a td having certain text in a table.

Here is the table structure I am working with.

<table id="quotes" width="100%" cellspacing="0" cellpadding="2">
<tbody>
<tr class="rowEven">
    <td>Store Pickup Store Pickup</td>     <!-- td content to be replaced by "hello" -->
    <td class="cartTotalDisplay">$0.00</td>
</tr>
</tbody>
</table>

I want to replace the above mentioned content with "hello"

Upvotes: 3

Views: 2050

Answers (3)

santho
santho

Reputation: 386

try it :

  $('#quotes tbody tr td:first-child').html('Hello');

Upvotes: 0

guradio
guradio

Reputation: 15555

$('#quotes tbody tr').find("td:contains('Store Pickup Store Pickup')").text('hello');

Use :contains()

Description: Select all elements that contain the specified text.

demo

Upvotes: 2

Pranav C Balan
Pranav C Balan

Reputation: 115222

You can use :contains() selector for that

$("td:contains('Store Pickup Store Pickup')").text('hello');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="quotes" width="100%" cellspacing="0" cellpadding="2">
  <tbody>
    <tr class="rowEven">
      <td>Store Pickup Store Pickup</td>
      <td class="cartTotalDisplay">$0.00</td>
    </tr>
  </tbody>
</table>

Upvotes: 3

Related Questions