I'm facing an issue with a table I have that includes a button in one of its columns. The button is supposed to toggle the class of the current row in the table and then replace itself once clicked.
$(document).ready(function() {
$(".checkOut").click(function() {
var currentRow = $(this).closest("tr");
$(currentRow).removeClass("checkedIn");
$(currentRow).addClass("checkedOut");
$(this).replaceWith('<button title="Check In" class="checkIn" value="true" name="check_in"><img alt="Check In" src="../images/check.png"></button>');
} );
$(".checkIn").click(function() {
var currentRow = $(this).closest("tr");
$(currentRow).removeClass("checkedOut");
$(currentRow).addClass("checkedIn");
$(this).replaceWith('<button title="Check Out" class="checkOut" value="true" name="check_out"><img alt="Check Out" src="../images/minus.png"></button>');
} );
});
Although the initial click works as intended, there seems to be an issue when trying to revert back to the original state - it's not working properly. It appears to be related to the usage of replaceWith. Any assistance on resolving this would be greatly appreciated!