I need to check, using jQuery, if any checkboxes on the page are checked. The particular checkbox set they are contained in doesn't matter, just any of them.
Any ideas?
Thanks!
var isChecked = $("input[type=checkbox]").is(":checked");
or
var isChecked = $('input:checkbox').is(':checked')
The following function returns true if there are any ticked checkboxes and false otherwise.
function anyCheckbox()
{
var inputElements = document.getElementsByTagName("input");
for (var i = 0; i < inputElements.length; i++)
if (inputElements[i].type == "checkbox")
if (inputElements[i].checked)
return true;
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With