The code snippet above defines a function called tablePush
that is supposed to push an id to a table when an item is clicked. However, there seems to be an issue as the function executes without a click event.
Below is the provided code block:
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());
}