I have five checkboxes. Using jQuery, how do I check if at least one of them is checked?
<
is()
can do this, and is arguably the only acceptable use of is(":checked")
:
From the jQuery docs, http://api.jquery.com/is/:
Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
alert($("input[name='service[]']").is(":checked"));
Example: http://jsfiddle.net/AndyE/bytVX/1/ (based on the fiddle by Brandon Gano)
Alternatively, and potentially faster, you can pass a function to is()
:
$("input[name='service[]']").is(function () {
return this.checked;
});