I want to prevent multiple submit if someone click on one of the submit buttons multiple times.
How can unbind or undelgate in this case the call of my custom function do_some_stuff that is only happens one time, because I try some of the jquery methods, but I think I did something wrong. Thanks
$(function() {
$('div.ajax').delegate('form button', 'click', function(e) {
$(this).do_some_stuff();
e.preventDefault();
});
});
Bind and unbind are deprecated in JQuery.
As of jQuery 1.7, the
.on()method is the preferred method for attaching event handlers to a document.http://api.jquery.com/on/
To answer your question about multiple submits, another new addition in JQuery 1.7 is the
.one()handler which, attaches an event handler to an object but only allows it to be fired once. This will allow you to prevent multiple submits.e.g:
Note I’m binding to the form submit event rather than a button click event.