Question

Can someone tell me how can I get tr id when dblclick event listens to tbody?
My table is as follows:

<table>
  <tbody id="patient_table">
    <tr id="1">
      <td class="td20">Patient Name</td>
      <td class="td20">Summary</td>
      <td class="td20">Created</td>
      <td class="td20">Last visit</td>
      <td class="td20">Refer to a Doctor</td>
    </tr>
    <tr id="2">
      <td class="td20">Patient Name</td>
      <td class="td20">Summary</td>
      <td class="td20">Created</td>
      <td class="td20">Last visit</td>
      <td class="td20">Refer to a Doctor</td>
    </tr>
  </tbody>
</table>

script is like follows:

$("tbody").on('dblclick','td',function (e) {
    var id = $(this).closest('tr').attr('id');
    alert(id);
});

This works here, but not in my code. When debugging it shows TypeError: $(...).on is not a function

BTW, I found this solution in another post.

Was it helpful?

Solution

Method on was introduced in jQuery version 1.7.

I think you have to upgrade your jQuery library to the newest version.

Otherwise, you can use live instead:

$("tbody td").live('dblclick',function (e) {
var id = $(this).closest('tr').attr('id');
alert(id);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top