Skip to content

Commit 7e53b0e

Browse files
committed
wesbos#10 my way
1 parent c639f0c commit 7e53b0e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,43 @@
9696
</div>
9797

9898
<script>
99+
let checkBoxes = document.querySelectorAll('.inbox input');
100+
let lastPressed
101+
let toCheck = false;
102+
checkBoxes.forEach(checkBox => checkBox.addEventListener('click', (e) => {
103+
if (e.shiftKey && lastPressed) {
104+
// console.log([...checkBoxes].indexOf(e.target));
105+
if ([...checkBoxes].indexOf(e.target) > [...checkBoxes].indexOf(lastPressed)) {
106+
for (let i = 0; i < checkBoxes.length; i++) {
107+
if (!toCheck) {
108+
if (checkBoxes[i] === lastPressed) {
109+
toCheck = true
110+
}
111+
} else {
112+
checkBoxes[i].checked = true;
113+
if (checkBoxes[i] === e.target) {
114+
toCheck = false;
115+
}
116+
}
117+
}
118+
} else {
119+
for (let i = checkBoxes.length; i > 0; i--) {
120+
if (!toCheck) {
121+
if (checkBoxes[i] === lastPressed) {
122+
toCheck = true
123+
}
124+
} else {
125+
checkBoxes[i].checked = true;
126+
if (checkBoxes[i] === e.target) {
127+
toCheck = false;
128+
}
129+
}
130+
}
131+
}
132+
} else {
133+
lastPressed = e.target;
134+
}
135+
}))
99136
</script>
100137
</body>
101138
</html>

0 commit comments

Comments
 (0)