Back to Snippets

Clicker Snippet.

This code builds a simple clicker game that counts how many times a button is clicked. It's a minimal example that demonstrates DOM updates and event handling using JavaScript.
How to Use?
Include the HTML for the clickable button and counter display, style it with CSS if desired, and link the JavaScript code. Every click increases the counter value in real-time — no external libraries required.
Credits
Inspired by beginner-friendly clicker game tutorials to teach state tracking and dynamic DOM manipulation using JavaScript.

<html>
<title>Clicker Clicker</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<body onbeforeunload="return closingCode()">
  <link rel="stylesheet" href="index.css">
    <script src="index.js"></script>
  <div class='topbar'>
    <a href='http://leemlam.github.io'>Clicker Clicker</a>
  </div>
    <center class='center'>
      <h1 id='total'>LB: 0</h1>
      <h5 id="click" style="font-family:trebuchet MS;">LB/click: 1 | LB/sec: 0</h5>
      <img class="round" src="https:
      <br><br>
      <button id='upgrade' class="round" onclick='upgrade("upgrade")' style="font-family:courier;">0-main upgrade: 15</button>
      <br><br>
      <button id='cat' class="round" onclick='upgrade("clicker cat")' style="font-family:courier;">0-clicker cat: 25 | +1/sec</button>
      <br><br>
      <button id='worker' class="round" onclick='upgrade("worker")' style="font-family:courier;">0-worker: 250 | +15/sec</button><br><br>
      <button class="settings" onclick="save()">Save</button>
      <button class="settings" onclick="load()">Load</button>
      <button class="settings" onclick="reset()">Reset</button><br><br>
    </center>
  </link>
</body>
</meta>

</html>