Если вам просто нужна сетка, попробуйте это:
[...document.querySelectorAll(".grid")].forEach((el,i) => {
el.setAttribute("data-pos", i);
el.addEventListener("click",function() {
let pos = this.getAttribute("data-pos");
this.innerText = "?";
console.log(pos%8,pos%10)
})
});
.grid { margin:2px }
<div id="container">
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><br/>
<span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span><span class="grid">⬜</span>
</div>
В качестве альтернативы используйте карту изображений - в моем сценарии позиционирование не точное, что вы можете исправить самостоятельно
document.querySelector("[name=image-map]").addEventListener("click",function(e) {
e.preventDefault();
let sq = e.target;
console.log(sq.title);
if (!sq.getAttribute("data-smile")) {
let d = document.createElement("div");
d.innerText = "?";
d.className = "smile";
// let coords = sq.getAttribute("coords").split(",");
// d.style.top = coords[1]+"px";
// d.style.left = coords[3]+"px";
d.style.left = e.clientX + "px";
d.style.top = e.clientY + "px";
sq.setAttribute("data-smile","yes");
document.getElementById("container").appendChild(d);
}
})
.smile { font-size: xx-small; position:absolute }
<!-- Image Map Generated by http://www.image-map.net/ -->
<div id="container">
<img src="https://juliannakunstler.com/images_art1/color/mono21.jpg" usemap="#image-map">
</div>
<map name="image-map">
<area target="" alt="0,0" title="0,0" href="" coords="7,6,22,21" shape="rect">
<area target="" alt="0,1" title="0,1" href="" coords="23,7,36,20" shape="rect">
<area target="" alt="10,8" title="10,8" href="" coords="144,111,156,125" shape="rect">
</map>