Skip to content

Instantly share code, notes, and snippets.

@smessing
Last active December 14, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smessing/5066406 to your computer and use it in GitHub Desktop.
Save smessing/5066406 to your computer and use it in GitHub Desktop.
A broken example for use in the DTSE lecture on JavaScript. Here the script runs before the HTML document loads!
body {
font-family: 'Arial';
font-size: 46px;
text-align: center;
}
.centered {
margin: 0 auto;
padding-top: 60px;
width: 600px;
}
table {
border: 1px solid black;
width: 100%;
}
td, tr {
padding: 10px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="table_color.css">
<script src="table_color_broken.js"></script>
</head>
<body>
<div class="centered">
<table>
<tr>
<td id="1-1">1-1</td>
<td id="1-2">1-2</td>
<td id="1-3">1-3</td>
<td id="1-4">1-4</td>
<td id="1-5">1-5</td>
</tr>
<tr>
<td id="2-1">2-1</td>
<td id="2-2">2-2</td>
<td id="2-3">2-3</td>
<td id="2-4">2-4</td>
<td id="2-5">2-5</td>
</tr>
<tr>
<td id="3-1">3-1</td>
<td id="3-2">3-2</td>
<td id="3-3">3-3</td>
<td id="3-4">3-4</td>
<td id="3-5">3-5</td>
</tr>
<tr>
<td id="4-1">4-1</td>
<td id="4-2">4-2</td>
<td id="4-3">4-3</td>
<td id="4-4">4-4</td>
<td id="4-5">4-5</td>
</tr>
<tr>
<td id="5-1">5-1</td>
<td id="5-2">5-2</td>
<td id="5-3">5-3</td>
<td id="5-4">5-4</td>
<td id="5-5">5-5</td>
</tr>
</table>
</div> <!-- .centered -->
</body>
</html>
var color_tile = function(i, j, delay) {
var cell_id = String(i) + "-" + String(j);
var cell_element = document.getElementById(cell_id);
console.log("Processing cell: " + cell_id);
var style = function() {
cell_element.style.backgroundColor = "#da0002";
};
setTimeout(style, delay * 100);
};
var delay = 1;
for (var i = 1; i < 6; i++) {
for (var j = 1; j < 6; j++) {
color_tile(i, j, delay);
delay += 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment