Reputation: 627
this is my code:
...
<td class="paymentStatus">@Model.paymentStatus</td>
<td><input type="checkbox" class="checkbox"/></td>
</tr>
What I'm wanting to do is that when the checkbox is checked set the paymentStatus td text to be "Payment Checked"
I tried this:
$(".checkbox").change(function () {
if ($(this).is(":checked")) {
$(this).closest('.paymentStatus').text("Payment Checked");
}
});
Doesn't work. Anyone know why and how to fix?
Upvotes: 0
Views: 135
Reputation: 123739
You need to use closest
to get to its parent td
and then to the sibling(td.paymentStatus)
to set the text.
$(".checkbox").change(function () {
if ($(this).is(":checked")) {
$(this).closest('td')
.siblings('td.paymentStatus')
.text("Payment Checked");
}
});
Upvotes: 2
Reputation: 173642
You have to move one level up and then select the previous sibling:
$(this)
.parent()
.prev('.paymentStatus')
.text('Payment checked');
Upvotes: 1