I've been programming a game and the part I want to mention here is - there's a form in which the person chooses the size of the board in which they're playing and I've done it successfully and it generates half a pyramid.
My main issue is that, in order to play, I need to pass my mouse over the element, it changes colour and then remove it by clicking on it. Whatever I do I can't seem to be able to do that on the element I choose, I can make it happen to the closest element there but never on the one I click on.
This is what I've got so far,
function selectTab() {
document.getElementById("tabuleiro").innerHTML = "";
var tamanho = document.getElementById("valorint").value;
if(tamanho<=10) {
console.log(tamanho);
var tab = document.getElementById("tabuleiro");
for(var i = 0; i<tamanho; i++) {
var linha = document.createElement('div');
for(var j = 0; j<i+1; j++) {
var coluna = document.createElement('div');
coluna.setAttribute("id", "coluna");
linha.appendChild(coluna);
coluna.addEventListener("click", function() {
playMove(this.id) }, false);
}
tab.appendChild(linha);
}
}
else {
console.log(tamanho);
alert("Isso é demasiado!");
}
}
function playMove(id) {
this.closest("div").remove();
}
I cannot use jQuery and I have only got a div that defines the board in HTML, not it's components.