The function tablePush
pushes an id to the table upon a click on an item.
However, it runs without a click and I don't understand why.
Here is my code:
function tablePush() {
console.log('OK');
if (pickPicture) {
console.log('TRUE');
} else {
console.log('on rentre dans le else');
console.log(this);
var idPic = this.getAttribute('id');
console.log(idPic);
table.push(idPic);
pickPicture = true;
}
}
var picture = document.getElementsByClassName('picture'),
table = [],
pickPicture = false;
for (var i = 0; i < picture.length; i++){
picture[i].addEventListener('click', tablePush());
}