You should wrap box in jQuery:
checkboxes = $("input[type=checkbox]"); checkboxes = _.filter(checkboxes, function(box) { return $(box).is(":checked"); });
In addition, instead of creating a new object for each individual item in the collection, you can simply use your own box.checked :
checkboxes = $("input[type=checkbox]"); checkboxes = _.filter(checkboxes, function(box) { return box.checked; });
On the side of the note: jQuery has its own filtering method :
checkboxes = $("input[type=checkbox]").filter(function() { return $(this).is(":checked"); });
Also, in your example - are you sure you need to filter? You can just as easily use this as your selector:
checkboxes = $("input[type=checkbox]:checked")
source share