-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
47 lines (44 loc) · 1.27 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<p> Master Checkbox</p>
<input type="checkbox" id="primary"> <br>
<input type="checkbox" class="secondary" value="1">
<input type="checkbox" class="secondary" value="2">
<input type="checkbox" class="secondary" value="3">
<input type="checkbox" class="secondary" value="4">
<input type="checkbox" class="secondary" value="5">
<input type="checkbox" class="secondary" value="6">
<script>
$(".secondary").on('change',function(){
array = [];
var checked = $('.secondary:checked');
checked.each(function(){
array.push($(this).val());
})
if(checked.length == $('.secondary').length){
$("#primary").prop('checked',true);
}
else{
$("#primary").prop('checked',false);
}
console.log(array);
})
$("#primary").on('change',function(){
var arr = [];
$(".secondary").prop('checked',true);
$(".secondary").each(function(){
arr.push($(this).val());
})
if($("#primary").prop('checked') == false){
$(".secondary").prop('checked',false);
arr = [];
}
console.log(arr);
})
</script>
</body>
</html>