Skip to content

Commit bc77d7b

Browse files
committed
ex finished
1 parent 7071024 commit bc77d7b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,40 @@
9797
</div>
9898

9999
<script>
100+
const checkboxes = document.querySelectorAll("input");
101+
console.log(checkboxes);
102+
103+
let lastChecked;
104+
105+
function handleCheck(e) {
106+
let inBetween = false;
107+
if(e.shiftKey && this.checked) {
108+
checkboxes.forEach(checkbox => {
109+
if(checkbox === this || checkbox === lastChecked) {
110+
inBetween = !inBetween
111+
}
112+
113+
if (inBetween) {
114+
checkbox.checked = true;
115+
}
116+
117+
});
118+
}
119+
120+
121+
lastChecked = this;
122+
123+
}
124+
125+
checkboxes.forEach(checkbox => checkbox.addEventListener("click", handleCheck));
126+
127+
// if one checkbox is checked && shift key is hold
128+
129+
130+
/* function checkMultipleCheckboxes(e) {
131+
e.shiftkey? checkboxes.check = true
132+
133+
} */
100134
</script>
101135
</body>
102136
</html>

0 commit comments

Comments
 (0)