0

Following a jQuery piece of code, I am trying to get the button icon which is inside the <button> of the next element which tells me if the icon is of trash type or something else so on that basis, I can write my logic

Trying it like this:

$(this).parent().next().find('td').eq($(this).index()-1).closest('button').html();

but I get this error:

and trying to find value of the next tr

<td>
<button type="button"><i class="fa fa-trash"></i></button></td>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jabbu
  • 15
  • 2

1 Answers1

0

Here is an working example

$("button").on('click', function() {
  console.log("next: " + $(this).closest('tr').next().find('td button').html());
  console.log("prev: " + $(this).closest('tr').prev().find('td button').html());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet" />
<table>
  <tbody>
    <tr>
      <td>
        <button type="button"><i class="fa fa-trash"></i></button>
      </td>
    </tr>
    <tr>
      <td>
        <button type="button"><i class="fa fa-trash"></i></button>
      </td>
    </tr>
  </tbody>
</table>
Krzysztof Janiszewski
  • 3,763
  • 3
  • 18
  • 38