Javascript button condition | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Javascript button condition

How do I add conditions to my button in javascript

20th Sep 2020, 12:11 AM
Haleu Bv
Haleu Bv - avatar
5 Respostas
+ 2
I'm not sure but I understand you correctly, you mean something like this? In the HTML; <button onclick="dothis"> Click be to do alert hu if your condition us true</button> In the JavaSricpt; var condition = true; //This cam be any condition though; function dothis(){ If(conditon==true/*You can make this any condition though, even tho check if 2<1*/){ //What you want to do; } }
20th Sep 2020, 12:45 AM
Vachila64ā˜•
Vachila64ā˜• - avatar
+ 3
Describe more in Description - what kind of condition is needed, and for what purpose. Clear and descriptive detail attracts contributors šŸ‘
20th Sep 2020, 12:35 AM
Ipang
+ 3
Divya Mohan thanksšŸ˜…, must have been a typo or somethingšŸ˜…
20th Sep 2020, 3:51 PM
Vachila64ā˜•
Vachila64ā˜• - avatar
+ 1
Vachila64ā˜• it would be onclick="dothis()" As you r a function here.
20th Sep 2020, 4:08 AM
Divya Mohan
Divya Mohan - avatar