Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<table class="@listitems.tablename">
     <thead>
          <tr>
              <th id="gradeName">@item.GroupLabel</th>
              <th id="selectCategory" class="grade_td">Select One</th>
              <th id="Comments">Comments</th>
</tr>
                    </thead>
<tbody>
 <td>text</td>
 <td><input type="radio" name="@items.ControlId" checked="@listItems.IsChecked" class="UnCheckOthers" id="@items.ControlId" value="@listItems.ControlValue"/>
                                                @listItems.ControlValue</td>
 <td class="Comments">comment</td>
</tbody></table>

<br />
   This is my table structure. Now i want to clear all the td:eq(2) from the above table when i click, any of the radiobuttons inside the table. I have written jquery code to do this task that works fine, for first row of the table how can i empty all the td inside this table using jquery.<br />

JavaScript
    $('.UnCheckOthers').click(function () {
        var className = $(this).closest('table').find('th:eq(0)').text();        
        $('.' + className.replace(/\s+/g, '').toLowerCase() + ' td:eq(2)').empty();
});

Can anyone give solution to this problem?
Posted
Updated 11-Jun-15 0:05am
v2
Comments
Thanks7872 11-Jun-15 6:03am    
If you have class over all the elements you want to remove then make use of it.

you need to add id of table body like


<tbody id="tbodyid">

after that

$('.UnCheckOthers').click(function () {
$("#tbodyid").empty();
});
 
Share this answer
 
v3
Comments
sankarisiva 11-Jun-15 6:31am    
thank you, but i want to empty only 3rd td.
sankarisiva 11-Jun-15 6:45am    
Thanks. I find solution
Try this one..

remove the nth column

$('table tr').find('td:eq(n),th:eq(n)').remove();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900