Hey developers! π
I'm currently going through #JavaScript30 β a fantastic 30-day vanilla JavaScript challenge, and today I hit Day 10.
The task?
Recreate that handy Shift + Click checkbox feature youβve probably used in Gmail, where you can select a range of checkboxes at once.
π― The Goal
Let users:
Click a checkbox
Hold down Shift
Click another checkbox
β Automatically select all checkboxes between them
π§ What Youβll Practice
This mini-challenge is great for improving:
Handling multiple checkbox events
Using the event.shiftKey property
Tracking user selections between clicks
Looping through elements conditionally
π Your Challenge
Try building this without any libraries or frameworks β just HTML, CSS (optional), and JavaScript.
Hereβs what you need:
- A list of checkboxes (10+ makes it fun!)
- An event listener on each checkbox
- A way to remember the last checked box
- Logic to check all boxes between the last and current if Shift is pressed.
π§ͺ Starter Hint
Youβll likely need to:
- Store the last checked checkbox in a variable
- Loop through all checkboxes to find the range using forEach.
- Use a flag (e.g. inBetween) to mark when to check/uncheck boxes
π¬ Want Help?
If you're stuck or want to compare your solution later, drop a comment! Iβll be sharing my approach in a follow-up post soon.
π Bonus: Try It Live
Iβve also made a live version of this if you want to test it directly:
π GitHub
πΉοΈ When you finish it publish with the #challengewithubba hashtag, so everyone would be able to see you solution!
π ENJOY!!
Top comments (0)