File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 104104 </ div >
105105
106106< script >
107+ const checkboxes = document . querySelectorAll ( 'input[type="checkbox"]' ) ;
108+
109+ let lastChecked ;
110+
111+ function handleCheck ( e ) {
112+ let inBetween = false ;
113+ //check if shift key pressed
114+ //And check of they are checking the checkbox
115+ if ( e . shiftKey && this . checked ) {
116+ //loop over every checkbox
117+
118+ checkboxes . forEach ( checkbox => {
119+ if ( checkbox === this || checkbox === lastChecked ) {
120+ inBetween = ! inBetween ;
121+ }
122+
123+ if ( inBetween ) checkbox . checked = true ;
124+ } ) ;
125+ }
126+
127+ lastChecked = this ;
128+ }
129+
130+ checkboxes . forEach ( checkbox => checkbox . addEventListener ( 'click' , handleCheck ) ) ;
107131</ script >
108132</ body >
109133</ html >
You can’t perform that action at this time.
0 commit comments