Prevent form from submitting via event.preventDefault(); not working
If the only thing you need to do is to prevent the default action, you can supply false
instead of a function:
$('#form').submit(false);
try return false
instead of event.preventDefault()
or accept event
as a parameter of your function.
$('#form').submit(function(event){
event.preventDefault();
});
Not sure why some people think this no longer works but here is an example showing it does still work.
https://jsfiddle.net/138z5atq/
Comment out the event handler and it will alert.
Regarding stopPropagation()
and stopImmediatePropagation()
they don't prevent the form from submitting at all. They just prevent the event from bubbling up the dom.
Other way is:
$('#form').submit(function(){
//some code here
return false;
});