Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable/disable Bootstrap buttons remotely using jquery? [duplicate]

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?

like image 825
kyr Avatar asked Jan 31 '26 17:01

kyr


1 Answers

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

like image 94
Arun P Johny Avatar answered Feb 02 '26 10:02

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!