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?
In the form 'submit' event, you don't know what button (or if any button) was clicked. In general, you use the 'submit' event when you want to do stuff after the form is submitted, like validate fields, which is usually what you want.
$("#something-%"). submit(function(e) { e. preventDefault(); $("#some-span"). html(data); });
The following should work:
var submit = curElement.closest('form').find(':submit');
This should work:
var curSubmit = $("input[type=submit]",curForm);
EDIT: Note the missing '
in the selector
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