File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 9797 </ div >
9898
9999< script >
100+ const checkboxes = document . querySelectorAll ( "input" ) ;
101+ console . log ( checkboxes ) ;
102+
103+ let lastChecked ;
104+
105+ function handleCheck ( e ) {
106+ let inBetween = false ;
107+ if ( e . shiftKey && this . checked ) {
108+ checkboxes . forEach ( checkbox => {
109+ if ( checkbox === this || checkbox === lastChecked ) {
110+ inBetween = ! inBetween
111+ }
112+
113+ if ( inBetween ) {
114+ checkbox . checked = true ;
115+ }
116+
117+ } ) ;
118+ }
119+
120+
121+ lastChecked = this ;
122+
123+ }
124+
125+ checkboxes . forEach ( checkbox => checkbox . addEventListener ( "click" , handleCheck ) ) ;
126+
127+ // if one checkbox is checked && shift key is hold
128+
129+
130+ /* function checkMultipleCheckboxes(e) {
131+ e.shiftkey? checkboxes.check = true
132+
133+ } */
100134</ script >
101135</ body >
102136</ html >
You can’t perform that action at this time.
0 commit comments