The code on this condition is not executed: if(example % 2 == 0) .
var check=$("#timer").html(); var example=check; if(example % 2 == 0 ) { $('#second').click(function() { $(this).css('background-image', 'url(X.png)'); example++; $("#timer").html(example); }); } else { $('#first').click(function() { $(this).css('background-image', 'url(Zero.png)'); example++; $("#timer").html(example); }); } .general { border: 1px solid #000000; width: 150px; height: 150px; background-color: #05EFFF; } table { margin: 0 auto; margin-top: 15%; } <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <meta http-equiv="Content-Type" content="text/html charsеt=utf-8"> <title>TIC-TAC-TOE</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" ></script> </head> <body> <table> <tr> <td><div id="first" class="general"></div></td><td><div id="second" class="general"></div></td><td><div id="third"class="general" ></div></td> </tr> <tr> <td><div id="fourth" class="general" ></div></td><td><div id="fiveth" class="general" ></div></td><td><div id="sixth" class="general" ></div></td> </tr> <tr> <td><div id="seventh" class="general" ></div></td><td><div id="eightth" class="general" ></div></td><td><div id="nineth" class="general" ></div></td> </tr> </table> <p id="timer" >1</p> <script type="text/javascript" src="js.js"></script> </body> </html> 

$("#timer").html();gets the string ....... you need an integer ...... you need to useparseIntdeveloper.mozilla.org/ru/docs/Web/JavaScript/Reference/… - Alexey Shimansky