4
$('#comment-form-subscribe input:checkbox:not(:checked)').prop("checked", true);

If checkboxes are unchecked, manually check them, but this doesn't seem to be working.

2
  • what version of jquery are you using? Commented Sep 17, 2012 at 7:08
  • 1
    Do you execute this on document ready? What is #comment-form-subscribe? If it is an ancestor of the checkboxes, your code should work fine. Commented Sep 17, 2012 at 7:08

2 Answers 2

4

You might have a selector issue: I'd check that the length of the jQuery object returned isn't 0. This is what I typically use:

EDIT: as @nbrooks pointed out, :input is deprecated. This might work:

$('#comment-form-subscribe').find('[type="checkbox"]').not(':checked').prop("checked", true);
Sign up to request clarification or add additional context in comments.

1 Comment

The :input selector is deprecated, and the rest is functionally identical.
0

try

$('#comment-form-subscribe input:checkbox:not(:checked)').attr('checked', true);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.