I don’t think there’s ever been a version of jQuery that supported what you’re doing in the new code.
Your code is calling cache
, then bindEvents
. You have this in cache
:
this.postForm = $('#postForm');
and this in bindEvents
:
$(document).on('submit', this.postForm, this.createPost);
So that means you’re calling on
and passing it an event name, a jQuery object, and a function.
Looking at the documentation, there’s no signature of on
that allows a jQuery object as the second argument.
I see that you’ve now posted your old code, which was using a selector string there, which does indeed work via event delegation:
$(document).on('submit', '#postForm', this.createPost);
If you want to handle the submit on the element itself without using delegation, then of course it would be:
this.postForm.on('submit', this.createPost);
0
solved $(document).on doesn’t work