+ 3

How to make button active after click and turn off it after second click?

https://code.sololearn.com/W2YtgVI8t38u/?ref=app

9th Jun 2020, 4:07 PM
Pavel Durov
Pavel Durov - avatar
2 odpowiedzi
+ 2
<!DOCTYPE html> <html> <style> input { height:50px; width:100px; } </style> <body> <center><input type="button" id="button" onclick="myfunc();" value="something"></input></center> <div></div> <script> var i=0; var n = 0; function myfunc () { var button = document.getElementById("button"); if (i==0) { button.style.backgroundColor=""; i++; n++; } else { button.style.backgroundColor="green"; i=0; } document.querySelector("div").innerHTML = "<p>n="+n+"</p><p>n="+i+"</p>"; } </script> </body> </html>
9th Jun 2020, 7:33 PM
JaScript
JaScript - avatar