Visitar URL original
Complete · wesbos/JavaScript30@2b29a8f · GitHub
Skip to content

Commit 2b29a8f

Browse files
committed
Complete
1 parent d8fe241 commit 2b29a8f

2 files changed

Lines changed: 27 additions & 137 deletions

File tree

‎10 - Hold Shift and Check Checkboxes/index-FINISHED.html‎

Lines changed: 0 additions & 137 deletions
This file was deleted.

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@
104104
</div>
105105

106106
<script>
107+
108+
const checkboxes = document.querySelectorAll('.inbox input[type = "checkbox"]');
109+
110+
let lastChecked
111+
112+
function handleCheck(e) {
113+
let inBetween = false;
114+
// check if the have the shift key down.
115+
// AND check if they are checking the box.
116+
if (e.shiftKey && this.checked) {
117+
//Loop over every single checkbox.
118+
checkboxes.forEach(checkbox => {
119+
if (checkbox === this || checkbox === lastChecked){
120+
inBetween = !inBetween;
121+
}
122+
if (inBetween) {
123+
checkbox.checked = true;
124+
}
125+
126+
})
127+
}
128+
lastChecked = this;
129+
}
130+
131+
132+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
133+
107134
</script>
108135
</body>
109136
</html>

0 commit comments

Comments
 (0)