1. Home
  2. Computing & Technology
  3. JavaScript

Noughts and Crosses

Part 1 : Sample and HTML

More of this Feature

JavaScript and Stylesheet

Another simple game that can be easily added to any web site. Almost everyone played noughts and crosses as a child (or tic-tac-toe as the Americans call it for some unexplainavle reason). Well now your web page can beat (or at least draw) with all comers when you add this ubobtrusive JavaScript to your page. First let's start with a working example to show you what it looks like. We'll use buttons for the nine squares to give it a nice neat appearance.

So now you've been beaten several times (or at best achieved a draw) the next step is to add the script to your page. Let's start by adding the HTML. You need this in the head of your page:

<script type="text/javascript src="ox.js"></script>
<link rel="stylesheet" type="text/css" href="ox.css">

And one tag in the body where you want the game to appear:

<div id="ox"></div>

and now all that remains is to create the ox.js and ox.css files.

Explore JavaScript
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2010 About.com, a part of The New York Times Company.

All rights reserved.