Moving all code into the

(function($) {
...
})(jQuery);

part solves the problem.