Skip to content

Instantly share code, notes, and snippets.

@attebury
Last active May 9, 2023 21:21
Show Gist options
  • Save attebury/10d12d99a13f99091889 to your computer and use it in GitHub Desktop.
Save attebury/10d12d99a13f99091889 to your computer and use it in GitHub Desktop.
Submit the form closest to a button.
/*
* A jQuery alternative to providing a custom ID selector to submit a form
* is to submit the form closest to the button that has been clicked.
* See http://api.jquery.com/closest/
*/
$('.js-btn-submit').on('click', function(e) {
e.preventDefault();
$(this).closest('form').submit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment