Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 477

Get row index of clicked button properly

$
0
0

I've tried several ways to get the row index of a clicked button inside a table.

The table:

while ($info = mysqli_fetch_array($sql)) {    echo "<tr>";        echo "<th>{$info['name']}</th>";        echo "<th>{$info['pass']}</th>";        echo "<th><a href='http://{$info['link']}'>{$info['link']}</a></th>";        echo "<th><div class='delbuttons'><button class='btn btn-info' data-toggle='modal' data-target='#myModal' id='{$info['id']}'>Delete</button></div></th>";    echo "</tr>";}?>

These are the ways that I've tried:

$(document).on('click', '.delbuttons button', function(event) {    alert($(this).index());}

but it always returns -1.

$(document).on('click','.delbuttons button', function(event) {    alert(this.rowIndex);}

This returns undefined.


Viewing all articles
Browse latest Browse all 477

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>