Skip to content

Instantly share code, notes, and snippets.

@thamognya
Created July 4, 2022 06:07
Show Gist options
  • Save thamognya/5f45ed88141feb9faea693e2efcde9e5 to your computer and use it in GitHub Desktop.
Save thamognya/5f45ed88141feb9faea693e2efcde9e5 to your computer and use it in GitHub Desktop.
A simple html + js counter
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Counter</h1>
<button id="mainButton">Increment Num</button>
<p id="number">0</p>
<script>
let counter = document.getElementById("number");
let counterNum = Number(counter.innerText);
let button = document.getElementById("mainButton");
button.addEventListener("click", () => {
counter.innerText = counterNum++;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment