From 5017da42b5e229ab742a3a9d704b0138f7dbaa60 Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Wed, 12 Feb 2020 17:25:20 +0100 Subject: [PATCH] 17h25 --- TD3/js/td3-exo1.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/TD3/js/td3-exo1.js b/TD3/js/td3-exo1.js index d6d11c9..bad24cc 100644 --- a/TD3/js/td3-exo1.js +++ b/TD3/js/td3-exo1.js @@ -3,16 +3,25 @@ console.log("Chargement..."); function init() { console.log("Initialisation..."); - var div = document.querySelectorAll('.case'); + var div = document.querySelectorAll(".case"); for (var i = 0; i < div.length; i++) { div[i].addEventListener("click", selection); } - //console.log(grille); } function selection(event) { - console.log(event.currentTarget.tagName); - var e = event.target; -} \ No newline at end of file + + var maCase = event.currentTarget; + var vide = document.body.querySelector(".case.vide"); + + if ((maCase.offsetTop == vide.offsetTop && Math.abs(maCase.offsetLeft - vide.offsetLeft == 102)) || + (maCase.offsetLeft == vide.offsetLeft && Math.abs(maCase.offsetTop - vide.offsetTop == 102)) { + maCase.setAttribute("class", ".case.vide"); + vide.setAttribute("class", ".case"); + } + + console.log(event.currentTarget.innerText); + var e = event.target; + } \ No newline at end of file