Last active
May 9, 2023 21:21
-
-
Save attebury/10d12d99a13f99091889 to your computer and use it in GitHub Desktop.
Submit the form closest to a button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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