previous

page 7

next
square clicking

First we'll need an onClick attribute;

change to squares.js
var s2="' onClick='square_clicked(this);'></div>";
square_clicked function in clicks.js
function square_clicked(el) {
var id=el.id;
var v0=g_squares[id];
var v=1; var colour='red';
if (v0==1) {v=0; colour='white';}
el.style.backgroundColor=colour;
g_squares[id]=v;
}
index.html
<html>
<head>
<title>Life</title>
<link rel='stylesheet' href='styles.css'>
<script src='library.js'></script>
<script src='squares.js'></script>
<script src='globals.js'></script>
<script src='functions.js'></script>
<script src='clicks.js'></script>
</head>
<body>
<script>squares(); klear(); draw();</script>
</body>
</html>
previous
next