JQuery - disable remaining checkboxes when limit is reached

Relative newbie jQuery:

I want to display a set of flags from which the user can select five.

I have jquery code that is checked in jsfiddle, but it obviously does nothing.

Can anyone see what obvious thing I am missing?

I have a set of checkboxes and then the following javascript:

function countChecked() { var n = $("input:checked").length; alert(n); if (n == 5) { $(':checkbox:not(:checked)').prop('disabled', true); } else { $(':checkbox:not(:checked)').prop('disabled', false); } } $(":checkbox").click(countChecked); 

jsfiddle here

+4
source share
3 answers

Your code works fine, you just need to set the jQuery framework on the left side.

Update script

+3
source

you have Mootools 1.4.5 selected in your fiddle .. select jQuery 1.8.3 from the drop-down menu and it will work.

+2
source

Your jsfiddle does not work because you install it using mootolls and not jquery:

http://jsfiddle.net/Vg4ty/3/

 JQUERY 
+1
source

All Articles