最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Select appropriate tr in table - jquery - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

6 Answers 6

Reset to default 2

You 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

发布评论

评论列表(0)

  1. 暂无评论