Html – Find that contains a known selector

htmlhtml-tablejquery

I want to get the <tr> element of a table by knowing the ID of one of it's elements (div).

Here's what the table looks like in HTML:

<table id="table-0">
  <thead>
  <tr role="row">
   <th>house</th>
   <th>phone</th>
  </tr>
  </thead>
 <tbody>
 <tr class="odd">
  <td class="">
    <div id="56"></div>my house
  </td>
  <td class="">
    <div id="57"></div>1234
  </td>
 </tr>
</tbody>
</table>

So I would like to get the <tr> element that has a <td> element that contains a <div> with the ID 56 (in this example).

Here's what I tried in jQuery (data['id'] = 56):

 var tr = $("tr:has(td:has($(\"#\" + data['id']))))");

Best Answer

You can also find the tr by element Id :

var tr = $('#Id').closest("tr");

In your case :

var tr = $('#56').closest("tr");