Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 13, 2022. It is now read-only.

Commit 63d45f5

Browse files
committed
solution wesbos#10
1 parent 6b5d1ff commit 63d45f5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,31 @@
103103
</div>
104104
</div>
105105

106-
<script>
107-
</script>
106+
<script>
107+
const checkboxes = document.querySelectorAll('input[type=checkbox]');
108+
let lastChecked = null;
109+
110+
function handleCheck(evt) {
111+
let inBetween = false;
112+
113+
if (evt.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 =>
129+
checkbox.addEventListener('click', handleCheck)
130+
);
131+
</script>
108132
</body>
109133
</html>

0 commit comments

Comments
 (0)