previous

page 18

next
my cell_clicked function
function cell_clicked(el) {
if (el.style.borderColor!='green') {
if (g_cell1=='') { // first click
g_cell1=el; // remember
el.style.borderColor='blue'; // mark
} else {
if (g_cell1==el) { // re-click of same cell
g_cell1=''; // forget
el.style.borderColor='lightgrey';
} else { // check legal
if (el.className==g_cell1.className) {
g_cell1.style.borderColor='lightgrey';
var temp=el.textContent; // swap
el.textContent=g_cell1.textContent;
g_cell1.textContent=temp;
g_cell1=''; // forget
words_check();
}
}
}
}
}

For this to work you will need to add an onClick attribute to 12 cell lines in index.html and set up the global g_cell1.
Note that ids 5, 6, 9 and 10 don't need the onClick.

<div class='cell c1' id='0' onClick='cell_clicked(this);'></div>
previous
next