Skip to content

fixed bugs #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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