Skip to content

Commit d3feeb4

Browse files
committed
lesson wesbos#10 (multiplay checkbox)
1 parent 9ec7892 commit d3feeb4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

10 - Hold Shift and Check Checkboxes/index-START.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@
9696
</div>
9797

9898
<script>
99+
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
100+
let lastCheck;
101+
102+
function doCheck(e) {
103+
104+
let inBetween = false;
105+
if (this.checked && e.shiftKey) {
106+
107+
checkboxes.forEach(checkbox => {
108+
109+
if (checkbox === this || checkbox === lastCheck) {
110+
inBetween = !inBetween;
111+
}
112+
113+
if (inBetween) {
114+
checkbox.checked = true;
115+
}
116+
117+
118+
})
119+
}
120+
lastCheck = this;
121+
}
122+
123+
124+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', doCheck));
125+
126+
99127
</script>
100128
</body>
101129
</html>

0 commit comments

Comments
 (0)