Skip to content

Commit d69cf54

Browse files
committed
challenge wesbos#10
1 parent 26f3a26 commit d69cf54

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@
9797
</div>
9898

9999
<script>
100+
const checkboxes = document.querySelectorAll('.inbox input[type = "checkbox"]');
101+
console.log(checkboxes);
102+
103+
let lastChecked;
104+
105+
function handleCheck(e){
106+
let inBetween = false;
107+
if (e.shiftKey && this.checked){
108+
// go ahead and do what we please
109+
// loop over every single checkbox
110+
checkboxes.forEach(checkbox => {
111+
console.log(checkbox);
112+
if (checkbox === this || checkbox === lastChecked) {
113+
inBetween = !inBetween;
114+
console.log('Starting to check them in between!');
115+
}
116+
117+
if (inBetween) {
118+
checkbox.checked = true;
119+
}
120+
});
121+
}
122+
lastChecked = this;
123+
}
124+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
100125
</script>
101126
</body>
102127
</html>

0 commit comments

Comments
 (0)