How to get selected checkboxes value using JQuery?

How to get selected checkboxes value using JQuery?

Here 4 checkboxes with same class “chk” and now i want values of checked checkboxes values on a button click

<input type="checkbox" class="chk" id="filterCheckboxSub" value="1" 
<input type="checkbox" class="chk" id="filterCheckboxSub" value="2" 
<input type="checkbox" class="chk" id="filterCheckboxSub" value="3" 
<input type="checkbox" class="chk" id="filterCheckboxSub" value="4" 
<button type="button" id="btnFilter">Filter</button>

Here the jquery code for getting value of selected checkboxes.

 $('#btnFilter').click(function () {

            var chkArray = [];

            $(".chk:checked").each(function () {
                chkArray.push($(this).val());
            });

            var selected;
            selected = chkArray.join(',');

            if (selected.length &gt; 0) {
                alert("You have selected " + selected);
            } else {
                alert("Please at least check one of the checkbox");
            }

        });