You need a separate 2D array that maintains state for each position (x, y) of the grid.
When a click occurs, check this state array to see if the cell has been clicked before, and refresh the canvas if necessary.
I created a small demo to show you: http://jsfiddle.net/alnitak/xN45K/
source
share