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 somet
In case you want to find the submit button of the form after it was submitted, you may find the following useful ... I use it to disable the submit button after the form was submitted to prevent multiple clicks.
$("form").submit(function () {
if ($(this).valid()) { // in case you have some validation
$(this).find(":submit").prop('disabled', true);
$("*").css("cursor", "wait"); // in case you want to show a waiting cursor after submit
}
});
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);
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
Because a HTML5 submit button may be out of form tag http://www.w3.org/TR/html-markup/input.submit.html#input.submit.attrs.form, you can use the following code to find it:
$(curElement.closest('form').get(0).elements).filter(':submit')
Using plain javascript (without relying on jquery):
var curSubmit = curForm.querySelector('button[type="submit"]');