So I'm using Bootstrap for my project. Basically I want to have the Button disabled ("disabled" class) until the Click Count reaches a distinct number. JS Part:
var timesClicked = 0; //main click variable
var CPC = 5;
var up1cost = 100; //cost for upgrade 1
function btnClick(){
timesClicked = timesClicked + CPC; //increases clicks by 1
$("#timesClicked").html(timesClicked) //parses over via jquery
if(timesClicked <= up1cost){
$("#up1btn").addClass("disabled")
} else {
$("#up1btn").removeClass("disabled")
}
return true;
}
Optional HTML Part:
<p><a class="btn btn-primary btn-lg disabled" id="up1bt">Purchase: C100</a></p>
Any help?
You have a spelling mistake up1btn and up1bt - The button id is up1bt but your selector is #up1btn, change the button id to up1btn.
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With