Table structure:
<table class="ui celled table unstackable" id="tblHits">
<thead>
<tr>
<th>40</th>
<th>40</th>
<th>40</th>
<th>25</th>
<th>15</th>
</tr>
</thead>
<tbody>
<tr>
<td class="addNone" id="t01">01</td>
<td class="addNone" id="t02">02</td>
<td class="addNone" id="t03">03</td>
<td class="addNone" id="t04">04</td>
<td class="addNone" id="t05">05</td>
</tr>
</tbody>
</table>
Issue with clicking and changing classes:
$("#tblHits:has(td)").click(function(e) {
var clickedCell= $(e.target).closest("td");
if ( $('#t'+ clickedCell.text() + '').hasClass( "addNone" )) {
$("#tblHits td").removeClass("addNone");
$('#t'+ clickedCell.text() + '').addClass("addHit");
alert('Clicked table cell value is: <b> ' + clickedCell.text());
}
else if ( $('#t'+ clickedCell.text() + '').hasClass( "addHit" )) {
$("#tblHits td").removeClass("addHit");
$('#t'+ clickedCell.text() + '').addClass("addMiss");
alert('Clicked table cell value is: <b> ' + clickedCell.text());
}
else if ( $('#t'+ clickedCell.text() + '').hasClass( "addMiss" )) {
$("#tblHits td").removeClass("addMiss");
$('#t'+ clickedCell.text() + '').addClass("addNone");
alert('Clicked table cell value is: <b> ' + clickedCell.text());
});
Your input on resolving this issue is appreciated. Thank you!