I am making a website (just for fun) where you can play the game SET. Now an intermittent problem has cropped up which I do not understand.
The user selects squares by clicking on them (the board is made up of floated DIV elements with images inside of them). When clicked, the border of the DIV becomes yellow.
The unwanted behavior that is happening here is that when a user clicks on the first DIV to highlight it, another div becomes highlighted (see below). The worst part is that the problem happens only intermittently, maybe once out of every five times a user begins selecting a set. I am not sure what code to post as I really cannot guess what is the source of the error.
Here is the code that makes squares light up, although I am not at all sure that the error is in this code:
var myDown = isIOS ? "touchstart" : "mousedown";
$(".cell").on(myDown,function(event) {
if (declared == true) {
if ($(this).hasClass('on')) {
$(this).removeClass('on');
} else {
if ($('.cell.on').length <3) {
$(this).addClass('on');
}
}
if ($('.cell.on').length == 3) {
$submitButton.addClass('ready');
setTimeout(delayedSubmit,400);
}
}
});
Here is a screenshot of the problem:
The square that is highlighted in blue should not be highlighted at all. I clicked on the square in the third column, second row, and that square does have a yellow border to indicate that it was clicked.
In the end I guess I'm just hoping someone else will have had a similar experience with weird, unwanted DIV highlighting so as to suggest a possible cause.
EDIT: Here is a bit of the HTML
<div id="board" class="">
<div id="A1" class="cell">
<div class="box">
<a class="stretchy no-limit" href="#"><img class="spacer" src="/img/spacer.png" alt="spacer"><img class="sprite one empty" id="c0012" alt="card" src="/img/12.png"></a>
</div>
</div>
<div id="B1" class="cell">
<div class="box">
<a class="stretchy no-limit" href="#"><img class="spacer" src="/img/spacer.png" alt="spacer"><img class="sprite three empty" id="c2001" alt="card" src="/img/01.png"></a>
</div>
</div>
<div id="C1" class="cell">
<div class="box">
<a class="stretchy no-limit" href="#"><img class="spacer" src="/img/spacer.png" alt="spacer"><img class="sprite one solid" id="c0202" alt="card" src="/img/02.png"></a>
</div>
</div>
etc.