JSFiddle - React, Tailwind, and code Playground

HTML

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

<a href=?>navigate away</a>

JavaScript

$(window).bind('beforeunload', function() {
    var checkboxcount = $("input:checkbox:checked").length;
    if(checkboxcount > 0) {
        return 'Are you sure?';
    }
});