YeahItsBen
YeahItsBen

Reputation: 53

Make a button only do something after a certain number of clicks?

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!"

Upvotes: 0

Views: 986

Answers (2)

Ali
Ali

Reputation: 67

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>

Upvotes: 0

ellipsis
ellipsis

Reputation: 12152

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>

Upvotes: 1

Related Questions