0
Q:

javascript shift click checkboxes

const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
let lastChecked;

function handleCheck(e) {
  if ( e.shiftKey && this.checked ) {

    let inBetween = false;
    
    checkboxes.forEach( (checkbox, i) => {
      if ( checkbox === this || checkbox === lastChecked ) {
        inBetween = !inBetween;
      }

      if ( inBetween ) {
        checkbox.checked = true;
      }
    });
  }

  lastChecked = this;
}

checkboxes.forEach( input => input.addEventListener( 'click', handleCheck ));
0

New to Communities?

Join the community