Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions 10 - Hold Shift and Check Checkboxes/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@
<script>
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');

let lastChecked;
let lastChecked = 'none';

function handleCheck(e) {
// Check if they had the shift key down
// AND check that they are checking it
let inBetween = false;
if (e.shiftKey && this.checked) {
if (e.shiftKey && lastChecked != 'none' && this !== lastChecked) {
// go ahead and do what we please
// loop over every single checkbox
checkboxes.forEach(checkbox => {
Expand All @@ -124,11 +124,21 @@

if (inBetween) {
checkbox.checked = true;
}else{
if(checkbox !== this && checkbox !== lastChecked){
checkbox.checked = false;
}
}
});
}

lastChecked = this;
if(e.shiftKey && lastChecked != 'none'){
return;
}else if(this.checked == true){
lastChecked = this;
}else{
lastChecked = 'none';
}
}

checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
Expand Down