views:

63

answers:

3

I try to get jQuery object of a submit button in a specific form (there are several forms on the same page).

I managed to get the form element itself. It looks something like this:

var curForm = curElement.parents("form");

The current Element has the context HTMLInputElement. The several techniques I tried to get the according submit element of the form:

var curSubmit = curForm.find("input[type='submit']");
var curSubmit = $(curForm).find("input[type='submit']");    
var curSubmit = curForm.find(":submit");
var curSubmit = $(curForm).find(":submit");    
var curSubmit = $(curSubmit, "input[type='submit']");

the result is always the same (and very strange). The result that I get is the same element as "curElement".

So how can I get the right submit button?

+2  A: 

The following should work:

var submit = curElement.closest('form').find(':submit');
SLaks
+1 for :submit! So much easier to use those than attribute selectors.
Stuart Branham
+4  A: 

This should work:

var curSubmit = $("input[type=submit]",curForm);

EDIT: Note the missing ' in the selector

jigfox
that worked, thanks
leifg
+1  A: 

BTW: Last selector looks weird. It selects each curSubmit(hm?) in every input[type=submit] tag. May be you mean var curSubmit = $("input[type=submit]", curForm);

SpeCT