epa ... vocês gostam de complicar ...
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
table { width: 100%; }
</style>
</head>
<body>
<table>
<tbody>
<tr data-id="1">
<td>Linha 1 - Coluna 1</td>
<td>Linha 1 - Coluna 2</td>
<td><button>apagar</button></td>
</tr>
<tr data-id="2">
<td>Linha 2 - Coluna 1</td>
<td>Linha 2 - Coluna 2</td>
<td><button>apagar</button></td>
</tr>
<tr data-id="3">
<td>Linha 3 - Coluna 1</td>
<td>Linha 3 - Coluna 2</td>
<td><button>apagar</button></td>
</tr>
</tbody>
</table>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$("tr").click(function() {
alert('row clicked : ' + $(this).attr('data-id'));
});
$("button").click(function(ev) {
alert('button clicked : ' + $(this).parents('tr').attr('data-id'));
ev.stopPropagation();
});
});
</script>
</html>
↧