I am trying to learn javascript and i made a grid with some boxes in it and i'm trying to change the color of the grid box when i click on it. I know i can use jquery i did it and worked but i want to do this with javascript only so this is my code so far:
var grid = document.getElementsByClassName('box');
function changeColor(item) {
item.addEventListener('click', function() {
this.style.background = 'black';
});
};
grid.forEach(function(el) {
changeColor(el);
});
I feel like this needs 'bind' method and i dont know how bind works yet so is it possible to make it work without bind? Thank you.