i have the following code working fine:
let elements = document.querySelectorAll('.click-target');
function handler(ev) {
console.log(ev.target.id);
this.classList.toggle('selected');
}
elements.forEach(element => element.addEventListener('click', handler, true));
Unfortunately i don't get this code working using an arrow-function within the addEventListener:
elements.forEach(element => element.addEventListener('click', ev => {
handler(ev).bind(element);
}));
The result: this is undefined. Although i've read a lot about the JS 'this' i have to confess, i'm still not able to master this in a way i should. Please can anybody try to explain me in a simple and stupid way what i'm doing wrong?
Many thanks in advance, Slevin