On my page, there are two forms. I’d like to select only the one for which the submit button is clicked.
I would think the following should do the trick:
$("#signup,#login").submit(function(){
$(this).parent("form:first").css('background-color', 'red');
return false;
});
But with the “form:first” selector, nothing happens (likely because it is selecting the container div). Without the “form:first” selector, the container div is selected.
http://jsfiddle.net/tenfold/gupGD/
Can anyone help with what’s going on here? Many thanks.
You could just do
The submission event is bound to the form itself.
Also, you shouldn’t use
return false, but use the event as a parameter and callevent.preventDefault()