Skip to content

Commit dd23620

Browse files
author
Ryan
committed
day 6
1 parent 92d0b20 commit dd23620

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+
108+
const items = document.querySelectorAll('input[type="checkbox"]');
109+
let lastChecked;
110+
function handleClick(e) {
111+
let inbetween = false;
112+
113+
if (e.shiftKey && this.checked){
114+
items.forEach(item => {
115+
if ((item === this || item === lastChecked) && lastChecked) {
116+
inbetween = !inbetween;
117+
}
118+
119+
if (inbetween) {
120+
121+
item.checked = true;
122+
}
123+
124+
})
125+
};
126+
lastChecked = this;
127+
}
128+
items.forEach(item => item.addEventListener('click', handleClick));
129+
107130
</script>
108131
</body>
109132
</html>

0 commit comments

Comments
 (0)