JSFiddle - React, Tailwind, and code Playground
by RoryMcCrossan
HTML
<input type="checkbox" value="one"/> one
<input type="checkbox" value="two"/> two
<input type="checkbox" value="three"/> three
<input type="checkbox" value="four"/> four
<input type="checkbox" value="five"/> five
<input type="checkbox" value="six"/> six
<input type="checkbox" value="seven"/> seven
<input type="checkbox" value="eight"/> eight
<span id="sels">0</span> selected
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);