Skip to content

Instantly share code, notes, and snippets.

@gmelodie
Created January 27, 2019 17:57
Show Gist options
  • Save gmelodie/7730e3c09f06404e96106571a9f33504 to your computer and use it in GitHub Desktop.
Save gmelodie/7730e3c09f06404e96106571a9f33504 to your computer and use it in GitHub Desktop.
Hiding the buttons on tic-tac-toe game
<html>
<script type="text/javascript">
function getSelectedButton(form, name) {
let radios = form.elements[name];
for (button in radios) {
if (button.checked) {
return button;
}
}
}
function computePlay() {
let selected = getSelectedButton(document.getElementById('board'), 'play');
selected.style.visibility = "hidden";
}
</script>
<h1> Tic-tac-toe </h1>
<form id='board'>
<input type="radio" name="play" id="11">
<input type="radio" name="play" id="12">
<input type="radio" name="play" id="13">
<br>
<input type="radio" name="play" id="21">
<input type="radio" name="play" id="22">
<input type="radio" name="play" id="23">
<br>
<input type="radio" name="play" id="31">
<input type="radio" name="play" id="32">
<input type="radio" name="play" id="33">
<br>
<button onclick="computePlay()"> Play! </button>
</form>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment