Answer the question
In order to leave comments, you need to log in
How to correctly set and handle the Click event?
Good afternoon, colleagues!
There are links/buttons (just an example) that have data in their attributes:
<button data-link data-amount="10"><span>10</span></button>
<a href="" data-link data-amount="20"><span>20</span></a>
document.querySelectorAll('[data-link]').forEach(el => el.addEventListener('click', function(e) {
console.log(e.target);
e.preventDefault();
}));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question