+ 9
How to disable button after clicking it?
with anything? did i need any frameworks? how to do it?
21 Answers
+ 10
You can do <button onclick = "this.disabled = true; ">Click me!</button>, which will disable itself after you click it. Also, are you making a clicker game? It seems like it.
+ 6
You should write .disabled=true; in js😉
+ 6
Jiпбба Sоnа You are welcome😉
+ 5
Muhd Khairul Amirin Bin Yaacob
hmm... so "if" didnt effect .disabled options...
THANKS A LOT!👍👍👍👍
+ 5
Thanks Rowsej !!! i will do that step one by one! you are a kind people!👍👍👍
+ 4
Muhd Khairul Amirin Bin Yaacob
hmm... i tried to do .disabled but it didnt work
+ 4
Muhd Khairul Amirin Bin Yaacob i do that alredy... hmmm maybe i have to show you the code:
https://code.sololearn.com/WdKTjRnmuC5E/?ref=app
when the count become 50, you can tap "buy"
i want the button disabled after i tap "buy"
+ 4
Jiпбба Sоnа Emperor Bob Thanks! Because the this.disabled = true; is in the onclick event of the button, the this gets changed to the button itself. So then you can disable it easily ☺️
+ 4
Jiпбба Sоnа Are you making a clicker game?
+ 4
Rowsej yes... i dont know how so i want to make it step by step
+ 4
Jingga Sona Here are some quick steps:
1. Make a basic button so that when you click it (using JS), a score increases. (The score needs to have a label as well.) Style it as well, and make sure in the JS it increases the score by a variable called power, not just score++.
2. Make an upgrade button that is disabled at the start. Each time you press the clicker, then check if you have got a high enough score, and if you have, the un-disable the button (clicker.disabled = false;), take away the amount from the score, and then change the power.
3. Add more upgrade buttons, and some helpers. When you buy a helper, ever3y second it will add 1 (or any amount) to your score.
4. Make everything look really nice.
5. Have fun clicking away!
+ 4
Luis Oscar There is no javascript course about styling object.
+ 2
Rowsej thank you so much i was wondering how to use this.blank in js
+ 2
Rowsej WOWOWOWOW i didnt know that!!!! Thanks a lot!👍
+ 2
Note, you can pass 'this' to the function being called:
<button id="btn" onclick="a(this);">Disable me</button>
function a(element) {
element.disabled = true;
}
Passing 'this' works in expected ways with other elements too, like <select>
+ 2
Thanks Kirk Schafer! Now i learn so much way how to disable a button😀😀😀
+ 2
you can do that in javascript.
jingga sona ,you can take a javascript course in sololearn to master that.
+ 2
Thanks jingga sona .