jquery - Error 'value.is is not a function' when checking if a checkbox is checked -
i'm trying ensure @ least 1 checkbox in group remains checked, i'm having difficulty.
i have multiple checkboxes name starts post_type[
. function runs on('change')
call fine, problem occurring when check see if input checkbox checked, following error.
value.is
not function
can please me troubleshoot code? thanks.
$(document).ready(function($){ $('input[name^="post_type["]', '#site-search').on('change', function(){ var checks = $('input[name^="post_type["]'); var one_checked = is_one_checked(checks); if(one_checked === false){ $(this).attr('checked', 'true'); } }); }); function is_one_checked(checks){ var checked = false; // wheteher or not @ least 1 box checked (false default) $(checks).each(function(key, value){ if(value.is(':checkbox') && value.is(':checked')){ checked = true; } }); return checked; }
the reason why value.is(':checked')
doesn't work because in loop, value
passed raw dom object. .is()
jquery method, you'd have wrap value
in jquery object in order use it:
$(value).is(':checked')
Comments
Post a Comment