8. Easy as baking cookies!
“How can I limit the user to only select up to 3 checkboxes?”
Boring Method Way Cooler Method
$(quot;input:checkboxquot;).click(function(){ jQuery.fn.limit = function(n) {
var boxes = $(‚input:checkbox‛); var self = this;
if(boxes.filter(‚:checked‛) return this.click(function(){
.length < 3) { return self
this.checked = true; .filter(quot;:checkedquot;).length<=n;
} });
}); };
$(quot;input:checkboxquot;).limit(3);