jquery exercises

jQuery: Finds all elements that are checked or selected

jQuery Fundamental - II : Exercise-55

Finds all elements that are checked or selected

Sample solution :

HTML Code :

<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Finds all elements that are checked or selected.</title>
<input type="checkbox" name="color" value="Bike">Red
<input type="checkbox" name="color" value="Car">Green
<input type="checkbox" name="color" value="Car">Blue
<input type="checkbox" name="color" value="Car">Black

JavaScript Code :

var count_Checked = function() {
var n = $( "input:checked" ).length;
$( "p" ).text( n + (n === 1 ? " is" : " are") + " checked." );
$("input[type=checkbox]" ).on( "click", count_Checked );

See the Pen jquery-fundamental-exercise-55 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Previous: Finds all checkbox inputs.
Next: Finds the checked radio input.

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming