Brian
Brian

Reputation: 115

count clicks for each specific link

I have a page of distinct links. I'm trying to create a JavaScript counter that counts how many times each individual link has been clicked.

I can count general clicks on any <a href> element. How can I count clicks on each individual link?

So,

  1. Bookmark #1 - Cracked.com - Clicked 3 times
  2. Bookmark #2 - Collegehumor.com - Clicked 1 times
  3. etc...

var clickcounts = '0';

function count() {
  clickcounts++;
  alert(clickcounts);
}
<a href="javascript:count();">count clicks</a>

Upvotes: 0

Views: 387

Answers (0)

Related Questions