简体   繁体   中英

Jquery trying to get value from inner table inside tr

<tr role="row" class="odd">
  <td style="background-color:white">
    <table>
      <tbody>
        <tr data-row-id="22">
          <td id="pid"><input type="checkbox" class="sub_chk" value="8843" data-id="22"><label class="pid 8843">8843</label></td>
          <td style="width: 120px">QCH/H3E/TCZN0D </td>
          <td style="width: 270px">Territory Health Intermediate Hospital 500 With Essential Extras </td>
        </tr>
        <tr>
          <td colspan="3">
            <button class="btn btn-success 8843 pull-right" id="approve-row" data-id="22" href="javascript: void(0)" style="display:none">
                <i class="glyphicon glyphicon-plus">Approve</i>
            </button>
          </td>
        </tr>
      </tbody>
    </table>
  </td>
  <td style="padding:0">
    <table>
      ----
    </table>
  </td>
</tr>

I am using jQuery datatable and in each row I have tables with inner tables. I am able to get the required table from the datatable list using:

$(this).closest('table').closest('table tr')[0]

But I am not able to get the pid value which is inside

<label class="pid 8843">

I want to find the pid value. Each row has different pid values. For example:

  <label class="pid 2">
  <label class="pid 3">
  <label class="pid 4">
  ...

I have found the correct tr in which my pid value resides but how to get the pid value is a problem.

Any help would be appreciated.

if the structure is same in you table, just target label and class to get that attr,, like this:

:EDIT (target input, even better)

$( $(this).closest('table').closest('table tr')[0] ).find('input').val()

try again please

Try this:

$('button').closest('table').find('tr:first td:first').find('label').attr('class')

 console.log($('button').closest('table').find('tr:first td:first').find('label').attr('class')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tbody> <tr> <td id="pid"><input type="checkbox" class="sub_chk" value="8843" data-id="22"><label class="pid 8843">8843</label></td> <td style="width: 120px">QCH/H3E/TCZN0D </td> <td style="width: 270px">Territory Health Intermediate Hospital 500 With Essential Extras </td> </tr> <tr> <td colspan="3"> <button class="btn btn-success 8843 pull-right" id="approve-row" data-id="22" href="javascript: void(0)"> <i class="glyphicon glyphicon-plus">Approve</i> </button> </td> </tr> </tbody> </table> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM