Check all checkboxes in HTML table using jQuery

Today, We want to share with you Check all checkboxes in HTML table using jQuery.In this post we will show you Check All Checkboxes with JQuery, hear for Select table rows that contain checked checkbox using jQuery we will give you demo and example for implement.In this post, we will learn about Jquery select all checkboxes in HTML table with an example.

Check all checkboxes in HTML table using jQuery

There are the Following The simple About Check all checkboxes in HTML table using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop Multiple Checkbox Select/Deselect using jQuery, so the some major files and Directory structures for this example is following below.

  • index.html

Check All Checkboxes with JQuery

How to Check and uncheck all using jQuery

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<html>
   <head>
      <title>Check All Checkboxes with JQuery</title>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"
         charset="utf-8"></script>
      <script language="javascript" type="text/javascript">
         $(document).ready(function()
         {
         $("#selectall").live('click',function(event){
         $('input:checkbox:not(#selectall)').attr('checked',this.checked);
         });
         
         
         $('input:checkbox:not(#selectall)').live('click',function(event)
         {
         if($("#selectall").attr('checked') == true && this.checked == false)
         $("#selectall").attr('checked',false);
         if(this.checked == true)
         CheckSelectAll();
         });
         
         
         function CheckSelectAll()
         {
         var flag = true;
         $('input:checkbox:not(#selectall)').each(function() {
         if(this.checked == false)
         flag = false;
         });
         $("#selectall").attr('checked',flag);
         }         
         });
      </script>
   </head>
   <body>
      <table width="50%" cellspacing="0" border="0" align="left" id="tblDisplay" cellpading="0"
         style="font-family: verdana; font-size: 10px;">
         <thead>
            <tr id="chkrow">
               <th>
                  <input type="checkbox" id="selectall" />
               </th>
               <th>
                  Sr.
               </th>
               <th style="text-align: left;">
                  User Name
               </th>
               <th style="text-align: left;">
                  Sir Name
               </th>
               <th>
                  Country
               </th>
               <th>
                  Marital Status
               </th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>
                  <input type="checkbox" value="1" />
               </td>
               <td>
                  1
               </td>
               <td style="text-align: left;">
                  Mayur
               </td>
               <td style="text-align: left;">
                  Dhameliya
               </td>
               <td>
                  Bhavanagar
               </td>
               <td>
                  Single
               </td>
            </tr>
            <tr>
               <td>
                  <input type="checkbox" value="2" />
               </td>
               <td>
                  2
               </td>
               <td style="text-align: left;">
                  Ankit
               </td>
               <td style="text-align: left;">
                  Kathiriya
               </td>
               <td>
                  Khijadiya
               </td>
               <td>
                  Marital
               </td>
            </tr>
            <tr>
               <td>
                  <input type="checkbox" value="3" />
               </td>
               <td>
                  3
               </td>
               <td style="text-align: left;">
                  Krunal
               </td>
               <td style="text-align: left;">
                  Sisodiya
               </td>
               <td>
                  Rajkot
               </td>
               <td>
                  Single
               </td>
            </tr>
            <tr>
               <td>
                  <input type="checkbox" value="4" />
               </td>
               <td>
                  4
               </td>
               <td style="text-align: left;">
                  Jaydeep
               </td>
               <td style="text-align: left;">
                  Gondaliya
               </td>
               <td>
                  USA
               </td>
               <td>
                  No-status
               </td>
            </tr>
         </tbody>
      </table>
   </body>
</html>

Jquery select all checkboxes in HTML table

How to Check and uncheck all using JavaScript

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<html>
	<head>
		<title>JavaScript - Select/Unselect (Check/Uncheck) all CheckBoxes on Button Click.</title>
		<script type="text/javascript">
			function selectAll(){
				var devlopers =document.getElementsByName('dev');
				for(var i=0; i<devlopers.length; i++){
					if(devlopers[i].type=='checkbox')
						devlopers[i].checked=true;
				}
			}
			
			function UnSelectAll(){
				var devlopers=document.getElementsByName('dev');
				for(var i=0; i<devlopers.length; i++){
					if(devlopers[i].type=='checkbox')
						devlopers[i].checked=false;
				}
			}			
		</script>
	</head>
<body style="text-align: center;">
	<h1>Pure JavaScript - Select/Unselect (Check/Uncheck) all CheckBoxes Example.</h1>
	<big>Select your favourite devlopers: </big><br>
	<input type="checkbox" name="dev" value="Jaydeep">Jaydeep<br>
	<input type="checkbox" name="dev" value="Chirag">Chirag<br>
	<input type="checkbox" name="dev" value="Ankit">Ankit<br>
	<input type="checkbox" name="dev" value="Krunal">Krunal<br>
	<p>
		<input type="button" onclick='selectAll()' value="Check All"/>
		<input type="button" onclick='UnSelectAll()' value="uncheck All"/>
	</p>
</body>

</html>

Multiple Checkbox Select/Deselect using JavaScript
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Check all checkboxes in HTML table using jQuery.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to Convert String to Object in Angularjs?
  2.   Laravel Ajax Bootstrap Toggle switch Update MySQL
  3.   Bootstrap Autocomplete Search Box / textbox in PHP MySQL
  4.   jquery uncheck all checkboxes Multiple Checkbox Example
  5.   How to Check Laravel Version by CLI and File
  6.   Remove particular value from jquery Array
  7.   Laravel 5.8 AJAX Tutorial Example From Scratch
  8.   Multiple Checkbox Check Uncheck All using jQuery
  9.   Transpose of a matrix in Java Program
  10.   how to upload images in wordpress by custom code?