The good thing about jQuery is that we can extend the library very easily, and today we are going to extend it to add a function that will allow us to limit the maximum number of checked checkboxes, something that can be really interesting.
First step: Add the limitCheckbox function to jQuery:
$ .fn.limitarCheckbox = function (num) {var check = this;
this.click (function () {return (check.filter (": checked"). length <= num);}); / * We take the number of checked checks and see if they exceed our parameter * /}
Second step: We execute the function in the document.ready ()
$ ("Input: checkbox"). LimitCheckbox (6);/ * We can use any selector as long as it has checkboxes ... and you can limit it to whatever you want * /
I hope it helps you for a project, I had to do it out of necessity right now and I couldn't help but post it for you, creatives of the world!
can you specify a little more like? any more complete code examples?
GREAT !, Thanks for the contribution, I'm starting with php, jQuery and javaScrit and you helped me understand how to apply it to other functions, thanks !!