I have a page that needs to have a div to fade out when three checkboxes are checked. I am using the code below but it doesn’t work. Any suggestions why?
<script>
function countChecked() {
var n = $("input:checked").length;
if($("input:checked").length > 3) {
}
else
{
$(".chkExample")
.fadeTo(500, 0.2)
}
}
countChecked();
$(":checkbox").click(countChecked);
</script>
On a random side now :checkbox is actually depreciated. Use
[type="checkbox"]as it will use native javascript to get them faster anyways.jsFiddle Demo