javascript - HTML button hit counting -


i make infinite game , wanted count clickings. tried nothing worked. i'm starter @ programming love now. please me! code (2 things: 1. sorry bad english; 2. tried copy best way code doesn't show everthing):

<html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8" />         <style type=text/css>             .button {                 background-color: red;                 float: center;                 width: 200px;                 height: 200px;                 margin-left: auto;                 margin-right: auto;                 display: block;                 margin-top: 300px;                 margin-bottom: 0%;             }              .body {                 background-color: yellow;             }          </style>     </head>      <body class="body" id="body">         <button onclick="myfunction()" class="button" style="font-size:50px" ; id="gomb">nyomj meg!</button>         <script>             var count = 0;             var = true;             var gomb = document.getelementbyid("gomb");             var body = document.getelementbyid("body");              gomb.onclick = function() {                 if (a == true) {                     gomb.style.background = "yellow";                     gomb.innerhtml = "na még egyszer!";                     body.style.background = "red";                     = false;                 } else {                     gomb.style.background = "red";                     body.style.background = "yellow";                     = true;                 }             };              function myfunction() {                 if (count == 5) {                     gomb.style.display = "none"                 } else {                     count = count + 1;                 };             }         </script>     </body> </html> 

try change code:

window.addeventlistener: rearrange code event click , variables assigned when page loaded.

use addeventlistener attach event html element

it's unusefull give id , name body.

var count = 0;  var = true;  var gomb;  var body;    window.addeventlistener('load', function(e) {    gomb = document.getelementbyid("gomb");    body = document.getelementsbytagname('body')[0];      gomb.addeventlistener('click', function(e) {      if (a==true){        gomb.style.background = "yellow";        gomb.innerhtml="na még egyszer!";        body.style.background = "red";        = false;      }      else      {        gomb.style.background = "red";        body.style.background = "yellow";        = true;      }    });  });    function myfunction(){    if(count==5) {      gomb.style.display="none"    }    else    {      count=count+1;    };  }
.button{    background-color:red;    float: center;    width: 200px;    height: 200px;    margin-left:auto;    margin-right:auto;    display:block;    margin-top:300px;    margin-bottom:0%;  }  body{    background-color: yellow;  }
<button onclick="myfunction()" class="button" style="font-size:50px"; id="gomb">nyomj meg!</button>


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -