peter88uk
peter88uk

Reputation: 327

Extract A Href from Table Cell and replace whole cell

I have this table structure which I can't change:

<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>

I then have this jQuery to remove the last table cell:

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

But not I just want to keep the a href on the last cell (removing the price).

Any suggestions?

Thanks.

Upvotes: 0

Views: 79

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Try

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

Demo: Fiddle

Upvotes: 2

Related Questions