Quick tip: Live event not trapping submit in IE

This problem manifested itself when a user clicked submit from a form that had been loaded in using AJAX to a jQuery UI dialog box.

Everything was fine in my development browsers, but in IE the user would be posted off to a new page.

The following live handler on a submit event will work in Firefox, Safari, etc, but the submit event is not captured in IE.

$('.myAjaxDiv form').live('submit', function(event) {
    // do stuff
});

A bug report has been filed, but it doesn’t look like this will be fixed any time soon.

Use delegate() instead of live()

The work around is to use the delegate event handler instead. The above code example would be rewritten as follows:

$('body').delegate('.myAjaxDiv form', 'submit', function(event) {
    // do stuff that IE can understand as well
});

Tags: ,

Leave a Reply