I have a page where a user needs to click two checkboxes before continuing (agree to two terms of service). My jQuery is fairly straightforward, you have to have both check boxes checked to continue:

$("#agree1, #agree2").click(function () {
    if ($("#agree1").is(':checked') == true && $("#agree2").is(':checked') == true) {
    } else {
        $("#nextPage").attr("disabled", "disabled");

I'm wondering if there is a simpler way of writing this. I expected a line like this to check for both boxes to be checked, but it doesn't:

if ($("#agree1 #agree2").is(':checked') == true)

Is there a way to simplify this?

Example code: jsFiddle


1 Answer 1


You can look for only the checked checkboxes, and then check that you found two:

if ($("#agree1:checked,#agree2:checked").length == 2) { ... }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.