-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop-hw.html
85 lines (75 loc) · 2.27 KB
/
loop-hw.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<title>Loops</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container {
display: flex;
}
.item {
padding: 10px;
margin: 5px;
border: 1px solid #000;
cursor: pointer;
}
.item.active,
.item:hover {
background: yellow;
}
.item .definition {
display: none;
}
.item.active .definition {
display: inline;
}
</style>
</head>
<body>
<div class="container">
<div class="item active">
<p class="word">Arch</p>
<span class="definition">A curved structure that spans an opening and usually supports weight from above.</span>
</div>
<div class="item">
<p class="word">Buttress</p>
<span class="definition">A projecting support built against an external wall, usually to counteract the lateral thrust of a vault or arch within.</span>
</div>
<div class="item">
<p class="word">Cantilever</p>
<span class="definition">A long projecting beam or girder fixed at only one end, used in bridge construction.</span>
</div>
<div class="item">
<p class="word">Dome</p>
<span class="definition">A rounded vault forming the roof of a building or structure, typically with a circular base.</span>
</div>
<div class="item">
<p class="word">Facade</p>
<span class="definition">The front of a building, especially an imposing or decorative one.</span>
</div>
</div>
<script type="text/javascript">
var itemEls = document.querySelectorAll('.item');
console.log(itemEls);
// Iterate through elements
for (var i = 0; i < itemEls.length; i++) {
var thisItem = itemEls[i];
console.log(thisItem);
// Add event listener
thisItem.addEventListener('click', function() {
// Iterate through elements
for (var j = 0; j < itemEls.length; j++) {
itemEls[j].classList.remove('active');
}
console.log(this);
var clickedEl = this;
clickedEl.classList.add('active');
});
}
</script>
</body>
</html>