Code24Lab

jQuery Collections Recap: Filter, Count & addClass on the Hire Desk

Lesson 1 of 20Lab

All lessons

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 20 is free. Unlock all 20 hands-on labs, the final exam and your certificate.

Buy course — CHF 19.90
Read first

The code in this lab

// Kestrel Cycle Hire – hire desk: one <tr class="booking"> per booking
var NOW = 17;                                     // current hour
var $rows = $('#bookings tr.booking');
var overdue = $rows
  .filter('[data-status="open"]')
  .filter(function () { return $(this).data('due') < NOW; })
  .addClass('overdue');
var deposits = 0;
$rows.filter('.ebike').each(function () {
  deposits += $(this).data('deposit');
});
$('#overdue-count').text(overdue.length);
Loading the lab…