5 Aug 2009
enable submit event on live bindings in jQuery
The live() method is one great new feature of jQuery 1.3, however it does not support binding of the event ’submit’ of forms.
$('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.
$('input:submit', $('form')).live('click', function() { // your callback }); |
Awesome! This helps a lot, I needed exactly this.
Matt
August 25th, 2009 at 12:04 ampermalink
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
August 26th, 2009 at 8:41 ampermalink
Does this apply only on live() handlers on the same objects or in general?
havvg
August 26th, 2009 at 8:57 ampermalink
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
August 26th, 2009 at 1:41 pmpermalink