I have two different set of checkboxes. With the coffescript code below I set the maximum amount of checkable items at 3. I would like to refactor this code, to be cleaner and compact, but I can't get it.
$("div.feature_list :checkbox").click ->
if $("div.feature_list :checked").length >= 3
$("div.feature_list :checkbox:not(:checked)").attr "disabled", "disabled"
$("div.feature_list :checkbox:not(:checked)").button disabled: true
else
$("div.feature_list :checkbox:not(:checked)").button disabled: false
$("div.style_list :checkbox").click ->
if $("div.style_list :checked").length >= 3
$("div.style_list :checkbox:not(:checked)").attr "disabled", "disabled"
$("div.style_list :checkbox:not(:checked)").button disabled: true
else
$("div.style_list :checkbox:not(:checked)").button disabled: false
.prop('disabled', true_or_false)
instead of setting the attribute. \$\endgroup\$