javascript - html button won't call function -


trying call function called "clear()" in javascript won't work, function works when put console won't when click button

<script type="text/javascript" src="nandc.js" ></script> <span id="status">player1's turn (x)</span> <br> <button onclick="btnclick(11)" id="11">&nbsp;</button> <button onclick="btnclick(12)" id="12">&nbsp;</button> <button onclick="btnclick(13)" id="13">&nbsp;</button> <br> <button onclick="btnclick(21)" id="21">&nbsp;</button> <button onclick="btnclick(22)" id="22">&nbsp;</button> <button onclick="btnclick(23)" id="23">&nbsp;</button> <br> <button onclick="btnclick(31)" id="31">&nbsp;</button> <button onclick="btnclick(32)" id="32">&nbsp;</button> <button onclick="btnclick(33)" id="33">&nbsp;</button> <br> <br> <button onclick="clear()" id="reset">reset</button> 

i'm new html , javascript there obvious errors?

var playerturn=true;  function btnclick(id) { if (document.getelementbyid(id).innerhtml!="&nbsp;") {     return; } if (playerturn == true) {     document.getelementbyid(id).innerhtml = "x";     statusmessage("player2's turn (o)"); } else {     document.getelementbyid(id).innerhtml = "o";     statusmessage("player1's turn (x)"); }  playerturn = !playerturn; } function statusmessage(text) { document.getelementbyid("status").innerhtml = text; } function clear() { playerturn=true; statusmessage("player1's turn (x)"); document.getelementbyid(11).innerhtml = "&nbsp;"; document.getelementbyid(12).innerhtml = "&nbsp;"; document.getelementbyid(13).innerhtml = "&nbsp;"; document.getelementbyid(21).innerhtml = "&nbsp;"; document.getelementbyid(22).innerhtml = "&nbsp;"; document.getelementbyid(23).innerhtml = "&nbsp;"; document.getelementbyid(31).innerhtml = "&nbsp;"; document.getelementbyid(32).innerhtml = "&nbsp;"; document.getelementbyid(33).innerhtml = "&nbsp;"; } 

edit: added more code allow problem reproduced

its problem function name, try change clearme()

use link below, code works fine..

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick

..if change function name clear not.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -