using closest, getting the value on clicking a button
Howdy
In a table with 3 cols and several rows, I have an int value on the first col and a button on the 2nd and 3rd. On clicking the button it should get the value of the first cell of its respective row and show it on the button. I have been given this here below, but while I understand what it pursues, still not coming on:
- function change(elem") {
$("elem").closest('tr').find('td:first').text();
}
</script>
and the HTML goes:
- <tbody>
@foreach ($polls as $vote)
<tr>
<td>{{ $vote->prenom}}</td>
<td>{{ $vote->nom}}</td>
<td>{{ $vote->tantieme }}</td>
<td><button type="button" onclick="change(this)" class="btn btn-success">VOTE OUI</button></td>
<td><button type="button" id="non" class="btn btn-danger">VOTE NON</button></td>
<td><button type="button" class="btn btn-info">ABSTENTION</button></td>
<td><button type="button" id="default" value = "230" class="btn btn-default">ABSENT</button></td>
</tr>
@endforeach
</tbody>
The additional tricky thing is that that is a polling table, so if anybody changes his mind before closing the polls, clicking on the button should toggle the value back to its original.