I cannot find a solution for that, I need to override a previously set submit event handler. In my example, I have a iframe page, with their own submit (which can have validation errors, and return false). So, I’m need to do:
$('<iframe></iframe>')
.load(function() {
content = $(this).contents()
form = content.find('form')
previous_form_submit = .... //This is my question
form.unbind("submit")
form.submit(function() {
var valid = previous_form_submit()
if (valid) {
$.post(form.attr('action'), form.serialize(), function(data) {
//do something
})
})
})
Edit: To be more clearer, the problem is override the event, but without losing previous handler with validation.
Edit2: I’m using jQuery 1.3.2
I’m going to another kind of solution, but I felt curious about how can do that.
Event handlers are stored in the element’s expando data store, accessible by
.data(), in this case,.data('events')for event handlers, then you do.submitfor bound submit handlers,.clickfor clicks, etc.jQuery 1.4+ version:
If the form had one submit handler it would look like this:
Otherwise you need to loop through them, using a
$.each()for example:jQuery 1.3.x version:
Using a
$.each()for example:It’s best to loop though here, as the indexes aren’t cleaned up. A handler may not be the first item, so
.submit[0]might beundefined, even if there is a handler.