I have a jquery ajax call that load a form inside a div and I want to prevent submit of this form but if I use jquery submit function with
$("form").submit(function(e){
e.preventDefault(e);
alert('submit intercept');
});
It does not work if I place in a external js file but works if I put in a script tag after the form that loaded via ajax call.
You can use $(document)
selector and on()
method for elements that are dynamically generated:
$(document).on('submit', 'form', function(e) {
e.preventDefault();
alert('submit intercept');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With