Skip to content

Instantly share code, notes, and snippets.

@RaneWallin
Last active April 7, 2020 02:01
Show Gist options
  • Save RaneWallin/626b6f4edab9df1087e0ad6e0bb91293 to your computer and use it in GitHub Desktop.
Save RaneWallin/626b6f4edab9df1087e0ad6e0bb91293 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<meta name="description" content="Webpage for xxxx">
<!-- http://meyerweb.com/eric/tools/css/reset/ -->
<link rel="stylesheet" href="css/reset/reset.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
<script>
// const btnClicked = function(elm, e) {
// console.log("test");
// console.log(e);
// };
document.addEventListener('DOMContentLoaded', function() {
let allBtns = [];
// {
// btn: btnElement
// count: someInt
// }
const addButton = () => {
let btns = document.querySelector(".btns");
let btn = document.createElement("button");
allBtns.push({
btn,
count: 0
});
btn.innerText = "0";
btns.appendChild(btn);
btn.addEventListener("click", (e) => {
allBtns.map(btnEntry => {
if (btnEntry.btn === e.target) {
btnEntry.count++;
btnEntry.btn.innerText = btnEntry.count;
addButton();
}
});
});
}
addButton();
}, false);
</script>
</head>
<body>
<div class="btns">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment