forked from niarogers/div-js-lesson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
70 lines (62 loc) · 1.94 KB
/
example.html
File metadata and controls
70 lines (62 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<html>
<head>
</head>
<style>
img {
width:50px;
height:50px;
}
.table {
display: table;
}
.tiles {
display: table-cell;
}
.row {
display: table-row;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//create the div with class table
var tableDiv = $("<div>", {
class:"table"
});
//appendTo will put the div between the body tag
tableDiv.appendTo("body");
//create a for loop the rows
for(var row = 0; row < 3; row++) {
//create the div with class row
var tableRow = $("<div>", {
class:"row"
});
//put the div between the div with class table
tableRow.appendTo(tableDiv);
//create the columns
for (var col = 0; col < 4; col++) {
var rockType = "rock.png";
if(row == 0 && col == 2) {
rockType = "whiteRock.png";
}
if(row == 1 && col == 1) {
rockType = "whiteRock.png";
}
if(row == 2 && col == 3) {
rockType = "whiteRock.png";
}
var imgCell = $("<img>", {
"src":rockType
});
var tableCell = $("<div>",{
class:"tiles"
});
imgCell.appendTo(tableCell);
tableCell.appendTo(tableRow);
}
}
});
</script>
<body>
</body>
</html>