File tree Expand file tree Collapse file tree
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9696 </ div >
9797
9898< script >
99+ const body = document . querySelector ( 'body' ) ;
100+ const inputs = document . querySelectorAll ( 'input[type="checkbox"]' ) ;
101+ let isShiftPressed = false ;
102+ let lastChecked = null ;
103+
104+ inputs . forEach ( input => input . addEventListener ( 'click' , handleCheckbox ) ) ;
105+ console . log ( inputs ) ;
106+
107+ function handleShift ( e ) {
108+ isShiftPressed = ! isShiftPressed ;
109+ }
110+
111+ function handleCheckbox ( e ) {
112+ console . log ( this . checked ) ;
113+ let inBetween = false ;
114+
115+ if ( isShiftPressed ) {
116+ inputs . forEach ( checkbox => {
117+ if ( checkbox === lastChecked || checkbox === this ) {
118+ inBetween = ! inBetween ;
119+ }
120+
121+ if ( inBetween ) {
122+ checkbox . checked = true ;
123+ }
124+ } )
125+ }
126+
127+ lastChecked = this ;
128+ }
129+
130+ body . addEventListener ( 'keydown' , handleShift )
99131</ script >
100132</ body >
101133</ html >
You can’t perform that action at this time.
0 commit comments