简体   繁体   中英

Trying to find out the next tr button fa icon

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>

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> 

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