Advertisement
Guest User

Untitled

a guest
Oct 1st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.   let clickableElements = document.querySelectorAll("a");
  3.  
  4.   clickableElements.forEach(a => a.addEventListener("click", addCount));
  5.  
  6.   function addCount(event) {
  7.     let clikedSite = event.target.parentElement.parentElement;
  8.     let clikedSiteParagraph = clikedSite.querySelector("p");
  9.     let clickCounter = clikedSiteParagraph.innerHTML.split(" ").map(e => Number(e)).filter(x => x)[0];
  10.     clickCounter++;
  11.  
  12.     clikedSiteParagraph.innerHTML = `visited ${clickCounter} times `;
  13.   }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement