How to Create a Select All Checkbox in JavaScript ? Last Updated : 16 Apr, 2024 Comments Improve Suggest changes Like Article Like Report In web apps with lots of checkboxes, a "Select All" checkbox is useful. It lets users check or uncheck all checkboxes at once, making things quicker. This feature can be implemented in various ways, such as utilizing JavaScript and JQuery to incorporate a "Select All" checkbox. This enhances the application's usability and speed, making it more user-friendly. Below are the methods to create a select all checkbox in JavaScript: Table of Content Using Vanilla JavaScriptUsing the jQuery LibraryUsing Vanilla JavaScriptIn this approach, create a webpage with checkboxes and a "Select All" checkbox using HTML and CSS. When the "Select All" checkbox is checked or unchecked, it toggles the selection status of all other checkboxes on the page using JavaScript. Example: The below example shows a "Select All" checkbox feature using JavaScript. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Select All Checkbox</title> <style> .d1 { display: flex; justify-content: center; align-items: center; height: 100vh; flex-direction: column; } .options_box { margin-top: 20px; } </style> </head> <body> <div class="d1"> <input type="checkbox" id="selectAllCheckbox"> Select All <br> <div class="options_box"> <input type="checkbox" class="checkboxes"> Checkbox 1 <input type="checkbox" class="checkboxes"> Checkbox 2 <input type="checkbox" class="checkboxes"> Checkbox 3 <input type="checkbox" class="checkboxes"> Checkbox 4 </div> </div> <script> document.getElementById('selectAllCheckbox') .addEventListener('change', function () { let checkboxes = document.querySelectorAll('.checkboxes'); checkboxes.forEach(function (checkbox) { checkbox.checked = this.checked; }, this); }); </script> </body> </html> Output: OutputUsing the jQuery LibraryIn this approach, When the "Select All" checkbox is toggled, it updates the selection status of all other checkboxes on the page using jQuery, allowing users to easily select or deselect all checkboxes at once. This improves user experience by providing a convenient way to manage checkbox selections Example: This example demonstrates a "Select All" checkbox feature using jQuery for streamlined management of multiple selections. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Select All Checkbox</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"> </script> <style> .d1 { display: flex; justify-content: center; align-items: center; height: 100vh; flex-direction: column; } .options_box { margin-top: 20px; } </style> </head> <body> <div class="d1"> <input type="checkbox" id="selectAllCheckbox"> Select All <br> <div class="options_box"> <input type="checkbox" class="checkboxes"> Checkbox 1 <input type="checkbox" class="checkboxes"> Checkbox 2 <input type="checkbox" class="checkboxes"> Checkbox 3 <input type="checkbox" class="checkboxes"> Checkbox 4 </div> </div> <script> $('#selectAllCheckbox').change(function () { $('.checkboxes').prop('checked', $(this).prop('checked')); }); </script> </body> </html> Output: Output Comment More infoAdvertise with us Next Article How to Create a Select All Checkbox in JavaScript ? H heysaiyad Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to get all checked values of checkbox in JavaScript ? A checkbox is a selection box that enables users to pick true or false in a binary manner by checking or unchecking it. When a checkbox is checked, it shows that the value has been chosen by the user, and when a checkbox is not checked indicates false which denotes that the user has not chosen the v 2 min read How to Select all Checkboxes in all Pages in jQuery DataTable ? Selecting all the table entries together at the same time in the jQuery data table can be achieved using the below methods. Before directly going to the implementation, first include the below CDN Links to your HTML document to implement the data table.Using the fnGetNodes() method of dataTableIn th 5 min read Create a Custom Checkbox using HTML CSS and JavaScript This article will show you how to create a custom checkbox using HTML, CSS, and JavaScript that enables users to check on checkboxes along with the " Select all " feature. We have written a code that generates a card in the center of the window. The card displays a list of items along with checkboxe 4 min read How to use Checkbox inside Select Option using JavaScript ? In this article, we are going to learn how to use Checkbox inside Select Option using JavaScript. ApproachThe HTML contains a styled dropdown (selectBox) and hidden checkboxes (checkBoxes).CSS styles enhance the appearance, styling the dropdown and checkboxes.The function showCheckboxes() toggles ch 2 min read How to Create a Checkbox in HTML? The checkbox is the HTML form element that lets users select one or more options from predefined choices. It can often be used when a user selects multiple items in the list. Checkboxes can be checked or unchecked, and they are created using the <input> tag with the type attributes set to the 3 min read How to get all selected checkboxes in an array using jQuery ? In this article, we are going to discuss various methods to get all the selected checkboxes in an array using jQuery. Several ways of doing this in jQuery are explained in detail with their practical implementation using code examples. Table of Content Using the array.push() method with each() metho 4 min read How to create an eye catchy Multiselect in jQuery ? In this article, we will create an eye catchy multi-select in jQuery. It is a selection menu in which we can select multiple values at the same time. For example, choosing different colleges.Step 1: First of all create an HTML file and add the following CDN links in the head tag.CDN link for jQuery: 3 min read How to use javascript function in check box? Checkboxes are used for instances where a user may wish to select multiple options, such as in the instance of a "check all that apply" question, in forms. HTML Checkboxes Selected. A checkbox element can be placed onto a web page in a pre-checked fashion by setting the checked attribute with a "yes 2 min read How to Create Multiple Selection Dropdown with Checkbox in Bootstrap 5 ? Bootstrap is a framework that is suitable for mobile-friendly web development. it means the code and the template available on Bootstrap are applicable to various screen sizes. It is responsive for every screen size. Dropdowns are built on a third-party library, Popper, which provides dynamic positi 3 min read How to select all Text in HTML Text Input when clicked using JavaScript? To select the text in HTML Text Input we can use the JavaScript DOM methods and we will select the text when we click the text box.Using document.getElementById() methodSyntax:<input onClick="this.select();" > or document.getElementById("ID").select();Example 1: We will use "this.select()" in 1 min read Like