Skip to content

Commit f8434b6

Browse files
committed
implemented the shift checkbox
1 parent 79dcd51 commit f8434b6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

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

106106
<script>
107+
var checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
108+
var lastChecked;
109+
110+
function handleCheck(e) {
111+
var inBetween = false;
112+
113+
if (e.shiftKey && this.checked) {
114+
checkboxes.forEach(checkbox => {
115+
if (checkbox === this || checkbox === lastChecked) {
116+
inBetween = !inBetween;
117+
}
118+
119+
if (inBetween) {
120+
checkbox.checked = true;
121+
}
122+
});
123+
}
124+
125+
lastChecked = this;
126+
}
127+
128+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
129+
107130
</script>
108131
</body>
109132
</html>

0 commit comments

Comments
 (0)