I am making a game of tic-tac-toe using HTML5, CSS and JavaScript. I have identified the winning patterns and more or less how to make it work. There is no artificial intelligence involved; it is intended to be a player-vs-player-on-the-same-computer game.
All I want to do is:
Please tell me if that is possible. If yes, how. Steps appreciated, don’t post complete code 🙂
3
Answers
It is possible, you should use javascript (JQuery) for this. You can register listeners for mouse click where you can catch the id of div that was clicked
Bind an event listener to the container, then examine the
target
property of the event object to determine which element was clicked.Seriously consider replacing the
<div>
s with<button>
s as they are designed to be interactive (so have benefits such as automatically appearing in the focus order).this
, if you are using jquery, it can be super simple:the above would check for any div with the class “box”, and add a “clicked” class to it
not sure why this was downvoted.. here is an example showing it working.. even for a sample of what I think was needed.
http://jsfiddle.net/LCKr6/1/