[2]. In my quest to implement a checkbox functionality using jQuery, I have composed the following code snippet:-
<!DOCTYPE html>
<html lang="en">
<head>
<title>Check Box using jQuery</title>
</head>
<body>
<form id="form">
<input type="checkbox" id="red" name="red" value="Red"/>Red
<input type="checkbox" id="green" name="green" value="Green"/>Green
<input type="checkbox" id="blue" name="blue" value=" Blue"/>Blue
<input type="checkbox" id="black" name="black" value="Black"/>Black<br/>
</form>
<div id="result">0 boxes are checked</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="chkbox.js"></script>
</body>
</html>
However, despite putting in effort into crafting the chkbox.js script as follows, the functionality is not being executed successfully:-
$(document).ready(function(){
var $checkboxes=$('#form td input[type="checkbox"]');
$checkboxes.change(function(){
var ccc=$checkboxes.filter(':checked').length;
$('span').text(ccc);
});
});
I am currently facing challenges determining why this code does not seem to be functioning correctly.