I want to change the check value from false to true whenever I click on the a link. So far I've not found any suggestions on how to do this
<a href="#" class="click"></a>
<a href="#" class="click">Click Me</a>
let check = false;
document.querySelectorAll('.click').forEach(item => {
item.addEventListener('click', event => {
check = true;
});
});
console.log(check);
console.log(check)inside the eventListenerconsole.log(check)gets executed right after you define your click event. It's not being called after you click or any other time after. If you look at yourcheckvariable after you've clicked, you'll find it's been set. You could add another click link that checks the value and shows it to the user in HTML or an alert if you want to test it out