Reputation: 110960
I have the following:
$('#xxxxx').submit(function() {
....
});
This is contained within a script that gets called w jQuery getScript... How can I make sure this bind only gets applied once? And or, clear out beforehand?
Thanks
Upvotes: 0
Views: 82
Reputation: 14049
Add a class to the form when attaching the handler. When attaching again, just check if the class is already added to the form.
var $xxxx = $('#xxxx')
if (!$xxxx.hasClass('handleradded')) {
$xxxx.submit(function(){
....
}).addClass('handleradded');
}
Solutions given by others are good ones. I just wanted to give you an alternative. :)
Upvotes: 0
Reputation: 5880
you can use 'unbind' :
$('#xxxxx').unbind('click').
bind('click', function() {
....
})
Upvotes: 1