5 Aug 2009

enable submit event on live bindings in jQuery

Posted by havvg

The live() method is one great new feature of jQuery 1.3, however it does not support binding of the event ’submit’ of forms.

?View Code JAVASCRIPT
$('form').live('submit', function() {
  // your callback
});

This can be simulated by a simple workaround on the selected objects. The click() event can be bound using the live() method. The workaround is simple: do not bind the submit of a form, but the click on any submit button within it.

?View Code JAVASCRIPT
$('input:submit', $('form')).live('click', function() {
  // your callback
});

Tags: ,

Subscribe to Comments

4 Responses to “enable submit event on live bindings in jQuery”

  1. Awesome! This helps a lot, I needed exactly this.

     

    Matt

  2. Do not (never ever!) use live(). Once you’ve got around 10 live()-handlers, the performance of the site will reduce drastically in most browsers (though performance in Opera will remain ok). Better use event bubbling instead.

     

    Tobi

  3. Does this apply only on live() handlers on the same objects or in general?

     

    havvg

  4. In general. Simply use event bubbling instead and everything will be fine.
    You can easily test the drawback of live() by creating a simple html-site where you add some handlers. You will notice that the performance will drop rapidly once you’ve got some live()-handlers.

     

    Tobi

Leave a Reply

Message: