user990016
user990016

Reputation: 3378

jquery how to select the nth-child of the current TD in a dynamic table

This is probably simple for some of you, but I'm having trouble with it. I want to get the value of the first TD in the TR of the TD that has a checkbox that has been checked. The line of code to alert the CSS of the nth-child is just my last attempt at selecting the TD.

$('.notdupe').live('click', function (e) {
        //alert("indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"));
        $.ajax({
          type: "POST",
          url: "cfc/basic.cfc?method=SetNotDupe",
          data: "indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"),
          error: function (xhr, textStatus, errorThrown) {
            // show error alert(errorThrown); 
          }
        });
        alert($(e.target:nth-child(-10)).css);
      });

<td class="dupegroup">#dupe_group_number#</td>
<td><input type="checkbox" name="UserIDList" value="#userid#" /></td>
<td><a href="#request.controlURL#individuals/?fa=viewIndiv" target="_blank">#userid</td>
<td>#lastname#</td> 
<td>#firstname#</td> 
<td>#nickname#</td>
<td>#companyname#</td> 
<td>#address1#</td>
<td>#zipcode#</td>
<td>#state#</td>
<td>client</td>    
<td align="center"><input class="notdupe" type="checkbox" name="indivID" value="#userid#" checked /></td>

Upvotes: 1

Views: 991

Answers (4)

Blazemonger
Blazemonger

Reputation: 92913

$td_you_want = $(this).closest('tr').children('td').first();

Upvotes: 1

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

You could try

$('.notdupe').live('click', function (e) {
        //alert("indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"));
        $.ajax({
          type: "POST",
          url: "cfc/basic.cfc?method=SetNotDupe",
          data: "indivNum=" + $(e.target).val() + "&SetValue=" + $(e.target).is(":checked"),
          error: function (xhr, textStatus, errorThrown) {
            // show error alert(errorThrown); 
          }
        });
        alert($(this).closest('tr').find('td:first').text());
      });

Upvotes: 1

Phil
Phil

Reputation: 380

$firstTD = $(this).parent().siblings().first()

Upvotes: 1

mVChr
mVChr

Reputation: 50185

In your click handler:

$(this).closest('tr').find('td:first')

Upvotes: 1

Related Questions