I'm building a plugin to submit forms with jQuery.
It needs to work with live elements, so I need to use $(document).on();
Here is an example of what I'm trying to accomplish:
$.fn.submittable = function() {
$(document).on('submit', this, function(event) {
event.preventDefault();
//Do whatever
});
};
$(document).ready(function() {
$('.tosubmit').submittable();
});
But $(this)
doesn't seem to work with .on()
if I do, $(this).submit(function(event) {});
it works fine.
Am I doing something wrong?