I'm new to JS and I'm learning, and I'm doing a game of the old one in which the first click is for the player1 to place the "x", and two clicks for the player2 to place the "o", how serious the best way to do because I can not add an "onclick" or "ondblclick" tag, I was trying to addEventListener by picking up the class, but I could not make it functional.
I'm using a table to create the board: current js code updated.
function testejogada(){
alert("funcionou");
}
function testejogada1(){
alert("funcionou1");
}
document.addEventListener('DOMContentLoaded', function(){
var classe = document.querySelector(".espaco");
classe.addEventListener('dblclick', function(){ testejogada()
});
classe.addEventListener('click', function(){ testejogada1()
});
});
<table align="center">
<tr>
<td><img class="espaco" src="img/default.png" id="casa1-1" /></td>
<td><img class="espaco" src="img/default.png" id="casa1-2" /></td>
<td><img class="espaco" src="img/default.png" id="casa1-3" /></td>
</tr>
<tr>
<td><img class="espaco" src="img/default.png" id="casa2-1" /></td>
<td><img class="espaco" src="img/default.png" id="casa2-2" /></td>
<td><img class="espaco" src="img/default.png" id="casa2-3" /></td>
</tr>
<tr>
<td><img class="espaco" src="img/default.png" id="casa3-1" /></td>
<td><img class="espaco" src="img/default.png" id="casa3-2" /></td>
<td><img class="espaco" src="img/default.png" id="casa3-3" /></td>
</tr>
<tr>
<td colspan="3" id="ganhador"></td>
</tr>
</table>