elena1234

How to add EventListener for "click" JavaScript

Oct 7th, 2021 (edited)
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2. let count = 0;
  3. let linkElements = document.querySelectorAll('.link-1 a')
  4. for (const item of linkElements) {
  5.     item.addEventListener('click',onLinkElementClick)
  6.      };
  7.  
  8.      function onLinkElementClick(e) {
  9.         let p = e.currentTarget.nextElementSibling;
  10.         let count = Number(p.innerText.split(' ')[1]);
  11.        count++;
  12.        p.innerText = `visited ${count} times`;
  13.      }
  14. }
  15.  
  16.  
Add Comment
Please, Sign In to add comment