File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 97
97
</ div >
98
98
99
99
< script >
100
+ const checkboxes = document . querySelectorAll ( '.inbox input[type = "checkbox"]' ) ;
101
+ console . log ( checkboxes ) ;
102
+
103
+ let lastChecked ;
104
+
105
+ function handleCheck ( e ) {
106
+ let inBetween = false ;
107
+ if ( e . shiftKey && this . checked ) {
108
+ // go ahead and do what we please
109
+ // loop over every single checkbox
110
+ checkboxes . forEach ( checkbox => {
111
+ console . log ( checkbox ) ;
112
+ if ( checkbox === this || checkbox === lastChecked ) {
113
+ inBetween = ! inBetween ;
114
+ console . log ( 'Starting to check them in between!' ) ;
115
+ }
116
+
117
+ if ( inBetween ) {
118
+ checkbox . checked = true ;
119
+ }
120
+ } ) ;
121
+ }
122
+ lastChecked = this ;
123
+ }
124
+ checkboxes . forEach ( checkbox => checkbox . addEventListener ( 'click' , handleCheck ) ) ;
100
125
</ script >
101
126
</ body >
102
127
</ html >
You can’t perform that action at this time.
0 commit comments