I'm creating a simple memory matching game and I want to compare the text-value of each clicked cell to see if a match is made. The click event handler at the bottom is my attempt to do so but I'm not sure how to save which cell was clicked. How do I save the text-value of each cell and compare them, while also saving which cell I'm comparing so I can hide it if the two cells that were clicked are not equal? Text-indent is set to 100%, and overflow is hidden by default.
var createTable = function (col, row) {
$('table').empty();
for (var i = 1; i <= row; i++) {
$('table').append($('<tr>'));
}
for (var j = 1; j <= col; j++) {
$('tr').append($('<td>'));
}
countCells = row * col;
};
createTable(4, 1);
var arr = [1, 2, 1, 2];
var pushNum = function () {
var len = arr.length;
for (var i = 0; i <= len; i++) {
var ran = Math.ceil(Math.random() * arr.length) - 1;
$('td').eq(i).append(arr[ran]);
arr.splice(ran, 1);
}
};
pushNum();
var match1;
$('td').click(function () {
$(this).css('text-indent', 0);
match1 = $(this).eq();
if (match1.val() === "1") {
alert("GOOD");
}
});