从表格单元格中提取A Href并替换整个单元格

时间:2013-10-02 12:02:57

标签: jquery

我有这个表格结构,我无法改变:

<table class="sui-opt-in">
    <tbody>
        <tr>
            <th></th>
            <th><strong>Time</strong>
            </th>
            <th><strong>Cost</strong>
            </th>
        </tr>
        <tr style="display: none;" id="labor_summary_for_1">
            <td> <a href="#" onclick="jQuery('#labor_for_1').show(); jQuery('#labor_summary_for_1').hide(); return false;">
            <i class="icon-right  "></i>
           Name Here
          </a>

            </td>
            <td>1m</td>
            <td>£0.75</td>
        </tr>
    </tbody>
    <tbody id="labor_for_1" style="display: table-row-group;">
        <tr>
            <td> <a href="#" onclick="jQuery('#labor_summary_for_1').show(); jQuery('#labor_for_1').hide(); return false;">
              <i class="icon-down  "></i>
              Name Here
            </a>

            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td>1m</td>
            <td>£0.75 <a href="#" onclick="new Ajax.Request('/tickets/remove_time_spent/1247', {asynchronous:true, evalScripts:true, method:'delete', parameters:'work_id=456&amp;selected_view=my_tickets' + '&amp;authenticity_token=' + encodeURIComponent('7hd72GGlOMJINFvnvio5c6z0CTtRyxNUdU8uMJrKhps=')}); return false;"><i class="icon-remove  "></i></a>

            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td><strong>Total</strong>
            </td>
            <td><strong>1m</strong>
            </td>
            <td><strong>£0.75</strong>
            </td>
        </tr>
    </tfoot>
</table>

然后我用这个jQuery删除最后一个表格单元格:

jQuery("#labor-section .sui-opt-in th:last-child, #labor-section .sui-opt-in  td:last-child").remove();

但不是我只想在最后一个单元格上保留一个href(取消价格)。

有什么建议吗?

感谢。

1 个答案:

答案 0 :(得分:2)

尝试

jQuery('#labor-section .sui-opt-in').find('th:last-child, td:last-child').contents().filter(function(){
    return this.nodeType == 3
}).remove();

演示:Fiddle

相关问题