How to make pressing the opposite effect?

Like when you press the button to cancel the action or to add a function which will return these elements back in place? The actual transfer of the items happens when you swap on this site serjo96.github.io/matrix
$(document).on("click",".change-mtrx", function(){
$('.matrix_a').appendTo('.matrix_b_cover');
$(".matrix_b").appendTo(".matrix_a_cover");
});
July 12th 19 at 16:39
1 answer
July 12th 19 at 16:41
Solution
$(document).on("click",".change-mtrx", function(){
 if ($(this).hasClass('flipped')) {
$('.matrix_a').appendTo('.matrix_a_cover');
$(".matrix_b").appendTo(".matrix_b_cover");
 } else {
$('.matrix_a').appendTo('.matrix_b_cover');
$(".matrix_b").appendTo(".matrix_a_cover");
}
$(this).toggleClass('flipped');
});

Find more questions by tags JavaScript