Checkmark the checkbox programmatically

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

If the boxes are unchecked, manually check them, but this does not work.

+4
source share
2 answers

You might have a selector problem: I would check that the length of the jQuery returned is not 0. This is what I usually use:

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

 $('#comment-form-subscribe').find('[type="checkbox"]').not(':checked').prop("checked", true); 
+4
source

to try

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

Source: https://habr.com/ru/post/1434546/


All Articles