-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
46 lines (46 loc) · 1 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<title>Testing let/var</title>
<style>
div {
height: 100px;
width: 100px;
display: inline-block;
margin: 20px;
}
#category0 {
background-color: aqua;
}
#category1 {
background-color: blue;
}
#category2 {
background-color: gray;
}
</style>
</head>
<body>
<div id="category0"></div>
<div id="category1"></div>
<div id="category2"></div>
<script>
'use strict';
for (var i = 0; i < 4; i += 1) {
(function(j) {
$('#category' + j).click(function navClickHandler() {
console.log(j);
});
}(i));
}
// the let key word will stay with the scope for each click handler
// for (var i = 0; i < 3; i += 1) {
// $('#category' + i).click(function navClickHandler() {
// console.log(i);
// });
// }
</script>
</body>
</html>