screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> </head> <body> <h1>Select Unselect all Checkboxes Javascript</h1> <label><input type="checkbox" id="selectAll"> Select All</label> <br> <label><input type="checkbox" class="checkbox-group"> Laptop</label> <label><input type="checkbox" class="checkbox-group"> Mobile</label> <label><input type="checkbox" class="checkbox-group">Tablet</label> <!-- Add more checkboxes as needed --> <script> // Get the master checkbox and all checkboxes in the group const masterCheckbox = document.getElementById('selectAll'); const checkboxes = document.querySelectorAll('.checkbox-group'); // Function to update all checkboxes based on the master checkbox function updateCheckboxes() { checkboxes.forEach(checkbox => checkbox.checked = masterCheckbox.checked); } // Attach an event listener to the master checkbox masterCheckbox.addEventListener('change', updateCheckboxes); // Attach event listeners to individual checkboxes to update the master checkbox checkboxes.forEach(checkbox => { checkbox.addEventListener('change', () => { // Update the master checkbox based on the state of individual checkboxes masterCheckbox.checked = Array.from(checkboxes).every(checkbox => checkbox.checked); }); }); </script> </body> </html>