-2

I have a HTML structure like below:

<tbody>
    <tr>
        <td></td>
        <td></td>
        <td><a booking="1" class="event_start"></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><a booking="1" class="booking_end"></td>
        <td></td>
        <td></td>
    </tr>
</tbody>

I need jQuery for booking_end click event which tells which row it is in, and which td booking_start is in, booking_start and booking_end are linked by an attribute booking.

So on click in above case I need output 2,3. where 2 is the tr number in which booking_end exists and 3 is the td number in which its booking_start exists.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

1

You can get the element index with its siblings. Use the index function that returns the zero-based index.

You will need to use the function on the row itself, e.g.

$('a').click(function()
{
     var self = $(this),
         row = self.closest('tr'),
         rowIndex = row.index();

     // do something with rowIndex
});
MacMac
  • 34,294
  • 55
  • 151
  • 222