I have a table that looks like this with many more columns (the number is context-dependent).
$('.action-checkbox').val(
$(this).parent().parent().find(".col-record_id").first().text().trim()
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tbody>
<tr>
<td>
<input type="checkbox" name="rowid" class="action-checkbox">
</td>
<td class="col-record_id">
10
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="rowid" class="action-checkbox">
</td>
<td class="col-record_id">
14
</td>
</tr>
</tbody>
But this sets an empty value.
What am I doing wrong?
Thanks in advance.
val()a callback method. You are just executing a statement. As such, the value ofthisis going to be whatever it is within the context of where the $('.action-checkbox') is called, rather than referring to each element found.