File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 104104 </ div >
105105
106106< script >
107+ const checkboxes = document . querySelectorAll ( '.inbox input[type="checkbox"]' )
108+
109+ let lastChecked ;
110+
111+ function handleCheck ( e ) {
112+
113+ let inBetween = false ;
114+ if ( e . shiftKey && this . checked ) {
115+ //loop over all checkboxes
116+ //see which was first
117+ //see which is last
118+ checkboxes . forEach ( checkbox => {
119+ console . log ( checkbox ) ;
120+ if ( checkbox === this || checkbox === lastChecked ) {
121+ inBetween = ! inBetween ;
122+ //inBetween is switched right when first is checked
123+ }
124+
125+ if ( inBetween ) {
126+ checkbox . checked = true ;
127+ }
128+ //inBetween is a flag variable
129+ } ) ;
130+ }
131+ lastChecked = this ;
132+ }
133+
134+
135+
136+ checkboxes . forEach ( checkbox => checkbox . addEventListener ( 'click' , handleCheck ) ) ;
137+
107138</ script >
108139</ body >
109140</ html >
You can’t perform that action at this time.
0 commit comments