refactoring: use jQuery method forEach to $.each, bind to on