It took me a while to extract this simple code from my huge form, please take a look at it:
<script type="text/javascript">
$(document).ready(function(){
$("form #formcontact").submit(function(){
alert('a');
return false;
});
});
</script>
<div>
<form id="formcontact" action="" method="POST">
<input id="contact_submit" type="submit" value="sub" />
</form>
</div>
This does not work but if I replace $("form #formcontact") with $("form") it works, but I don’t want it to be on every form.
Why is that? So strange.
$(“form #formcontact”) selects a child element of
<form>. Remove the space and it will work:or