Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion models/battleground.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ var BattleGround = (function() {
BattleGround.prototype.update = function() {
var self = this;
this.cellsElement.innerHTML = '';
this.area.forEach(function(el) {
this.area.forEach(function(el,index) {
var cell = document.createElement('div');
var cellElement = el.render();

cell.classList.add('game__cells__item');
cell.setAttribute('data-index',index + 1);
cell.appendChild(cellElement);
self.cellsElement.appendChild(cell);
});
Expand Down
15 changes: 15 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ var fnc = function(e) {
};

document.addEventListener('keydown', fnc);

// add event listener CASE 1
const gameCells = document.querySelectorAll('.game__cells__item');
gameCells.forEach((element, index) => {
element.addEventListener('mouseover', () => {
console.log(`You just moused over an element number ${index}`);
});
});

// add event listener CASE2
const gameWrapper = document.querySelector('.game__cells');
gameWrapper.addEventListener('mouseover', event => {
let index = event.target.getAttribute('data-index');
console.log(`You just moused over an element number ${index}`);
});