Skip to content

Commit c19293a

Browse files
committed
Exercise 10
1 parent a0a5805 commit c19293a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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+
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
108+
109+
let lastChecked;
110+
111+
function handleCheck(e) {
112+
//Check if shift key was held
113+
//And make sure they're checking it
114+
let inBetween = false;
115+
if (e.shiftKey && this.checked) {
116+
checkboxes.forEach(checkbox => {
117+
console.log(checkbox);
118+
if (checkbox === this || checkbox === lastChecked) {
119+
inBetween = !inBetween;
120+
console.log('Starting to check in between');
121+
}
122+
if (inBetween) {
123+
checkbox.checked = true;
124+
}
125+
});
126+
}
127+
lastChecked = this;
128+
// console.log(lastChecked);
129+
};
130+
131+
// console.log(checkboxes);
132+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
133+
107134
</script>
108135
</body>
109136
</html>

0 commit comments

Comments
 (0)