Skip to content

Instantly share code, notes, and snippets.

@kuznetsovandrey76
Created February 6, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuznetsovandrey76/f1c5f7d29cf932df375e65161125221e to your computer and use it in GitHub Desktop.
Save kuznetsovandrey76/f1c5f7d29cf932df375e65161125221e to your computer and use it in GitHub Desktop.
// HTML
<div id="first" class="content"></div>
<div id="second" class="content"></div>
//JS
var first = document.querySelector("#first");
var second = document.querySelector("#second");
var clickedLink = {
first: 0,
second: 0
}
var click = function(e) {
// switch - case
if(e.target.id === "first") {
clickedLink.first++;
}
if(e.target.id === "second") {
clickedLink.second++;
}
console.log(clickedLink);
}
// querySelectorAll
first.addEventListener('click', click);
second.addEventListener('click', click);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment