Skip to content

Instantly share code, notes, and snippets.

@saltun
Last active January 27, 2022 07:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltun/33a6f7e183abd45814cc5d1306b0ca58 to your computer and use it in GitHub Desktop.
Save saltun/33a6f7e183abd45814cc5d1306b0ca58 to your computer and use it in GitHub Desktop.
Select All Checkboxes with jQuery example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select All Checkboxes with jQuery - savascanaltun.com.tr</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</head>
<body>
<center>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br>
<hr/>
<input type="checkbox" id="selectAll" name="" >
<label for="selectAll"> Select All</label>
</center>
<script type="text/javascript">
$("#selectAll").click(function(){
$("input[type=checkbox]").prop('checked', $(this).prop('checked'));
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment