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 9999 </ div >
100100
101101< script >
102+ let checkboxes = document . querySelectorAll ( "input[type=checkbox]" )
103+ let lastCheckedBox
104+
105+ function setLastCheckedBox ( checkbox ) {
106+ console . log ( "setLastCheckedBox" )
107+ if ( checkbox . checked )
108+ lastCheckedBox = checkbox
109+ }
110+
111+ function checkInBetweenBoxes ( box1 , box2 ) {
112+ let doCheckBoxes = false
113+
114+ console . log ( "checkInBetweenBoxes" )
115+ checkboxes . forEach ( checkbox => {
116+ if ( checkbox === box1 || checkbox === box2 )
117+ doCheckBoxes = ! doCheckBoxes
118+
119+ if ( doCheckBoxes )
120+ checkbox . checked = true
121+ } )
122+ }
123+
124+ function handleCheck ( e ) {
125+ console . log ( lastCheckedBox )
126+ if ( lastCheckedBox && e . shiftKey && this . checked )
127+ checkInBetweenBoxes ( this , lastCheckedBox )
128+
129+ setLastCheckedBox ( this )
130+ }
131+
132+ checkboxes . forEach ( checkbox => {
133+ checkbox . addEventListener ( 'click' , handleCheck )
134+ } )
102135</ script >
103136</ body >
104137</ html >
You can’t perform that action at this time.
0 commit comments