JSFiddle - React, Tailwind, and code Playground

HTML

<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>

JavaScript

var maxCheckedCount = 5;
    var maxCheckedAlertMessage = 'Woops! Too many selected!';

        jQuery('input[type=checkbox]').click(function(){
            var n = jQuery('input:checked').length;
            if(n>=maxCheckedCount){
                jQuery(this).prop('checked',false);
                alert(maxCheckedAlertMessage);
            }
        });