0

Is there a way to make a button completely useless until a certain amount of clicks have been performed in HTML?

For example, a button that doesn't do anything when clicked until it has been clicked 100 times. On the 100th click it links to a separate page saying "Congratulations! You found a secret page!"

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
YeahItsBen
  • 43
  • 3

2 Answers2

1

You can use a counter to increment on click and at certain click you can run the functionality you want

var count = 0;

function a() {
  count++;
  if (count == 3)
    alert("pressed 3 times")
}
<button onclick="a()">click me 3 times</button>
ellipsis
  • 12,049
  • 2
  • 17
  • 33
0

You can use this to move to the other page by clicking 100 times.

var count = 0;


function func() {
count++;
 if (count == 100)
("#butn").href("your link here");
   }
 <button id="butn" onclick="func()"></button>
Ali
  • 57
  • 6
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Vasilisa Feb 20 '19 at 07:34