How can I select the tr tag containing USDTRY value in its second td and change its value with TRYUSD using jquery?
<table class="k-selectable" cellspacing="0" role="grid" data-role="selectable">
<tbody>
<tr role="row" data-uid="9d1c0ae7-ec5d-4377-ad61-9eace8158802">
<td role="gridcell">
<img src="/Images/up.png">
</td>
<td role="gridcell">USDTRY</td>
<td role="gridcell">1.30514</td>
<td role="gridcell">1.30527</td>
</tr>
<tr class="k-alt" role="row" data-uid="0ff48da9-2019-4cf8-b631-a09c3ce98d63">
<tr role="row" data-uid="2c9ae0ba-c744-4bbb-9a23-fd15a3b65b6c">
</tbody>
How can I select the tr tag containing USDTRY value in its second td and change its value with TRYUSD using jquery?
<table class="k-selectable" cellspacing="0" role="grid" data-role="selectable">
<tbody>
<tr role="row" data-uid="9d1c0ae7-ec5d-4377-ad61-9eace8158802">
<td role="gridcell">
<img src="/Images/up.png">
</td>
<td role="gridcell">USDTRY</td>
<td role="gridcell">1.30514</td>
<td role="gridcell">1.30527</td>
</tr>
<tr class="k-alt" role="row" data-uid="0ff48da9-2019-4cf8-b631-a09c3ce98d63">
<tr role="row" data-uid="2c9ae0ba-c744-4bbb-9a23-fd15a3b65b6c">
</tbody>
Share
Improve this question
edited Apr 18, 2013 at 12:51
tckmn
59.4k27 gold badges118 silver badges156 bronze badges
asked Apr 18, 2013 at 12:50
xkcdxkcd
2,58011 gold badges62 silver badges100 bronze badges
6 Answers
Reset to default 2You could use this snippet:
$('td[role="gridcell"]:contains("USDTRY")').text('TRYUSD');
Demo
You want to narrow down your selection as far as possible using regular selectors, then you can use the :contains
psuedoselector to search for your text:
$('table.k-selectable td:contains("USDTRY")').text('TRYUSD');
Perhaps not a perfect solution, but try this:
$('table.k-selectable tr td').each(function() {
if($(this).text() === 'USDTRY') {
$(this).text('TRYUSD');
}
});
$(selector).find("tr:contains('USDTRY ')");
or
$('tableId td:contains("USDTRY")').text('TRYUSD ');
Use the contains selector:
$('td:contains("USDTRY")').html('TRYUSD ');
you don't need to find tr
..just find td
with that text using filter()
and replace
$('td').filter(function(){
return $(this).text() == "USDTRY";
}).text('TRYUSD');
fiddle here