I am trying to fade a div out once a certain amount of check boxes are checked but I can't get it to work. I tried val and length but I believe I am not pulling the value the correct way for checkboxes?
$('input:checkbox').change(
function(){
if ($(this).is(':checked').val > 2) {
alert('checked');
}
});
Any input would be greatly appreciate. Thanks!
You can use a selector and check the number of elements found (length
indicates this).
$('input:checkbox').change(function() {
var numberChecked = $('input:checkbox:checked').length;
if (numberChecked > 2) {
// Fade your div out here
}
});
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