Multi-selection of Checkboxes on button click in jQuery?

For this, use jQuery() with id property. Following is the code −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="">
   .changeColor {
      color: red
<input type="button" id="selectDemo" value="Want To Select All
Values" />
<input type="checkbox" id="CheckBoxId1"
class="isSelected" /> Javascript
<input type="checkbox" id="CheckBoxId2"
class="isSelected" /> MySQL
<input type="checkbox" id="CheckBoxId3"
class="isSelected" /> MongoDB
<input type="checkbox" id="CheckBoxId4"
class="isSelected" /> Python
   jQuery("#selectDemo").click(function () {
      if (jQuery(this).hasClass("changeColor")) {
         jQuery(".isSelected").prop("checked", true);
         jQuery(this).val("Want To UnSelect All Values");
      } else {
         jQuery(".isSelected").prop("checked", false);
         jQuery(this).val("Want To Select All Values");

To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.


This will produce the following output −

Now I am going to click the above button “Want To Select All Values” −

Click the above button “Want To UnSelect All Values” −

Updated on: 14-Sep-2020


Kickstart Your Career

Get certified by completing the course

Get Started