jQuery.live()
A new way to setup events
$({selector}).live({event}, {handler}) An example would be creating a button that self-replicates.
$('button').live('click', function(){ $(this).after($(this).clone()); }); Now, every button on a page will insert a new button just after itself. While this isn't very useful, you will notice that the new click event is fired without adding extra event handlers. This is very useful when you are doing a lot of ajax manipulation; You can just set an initial event handler to a selector and it will automatically replicate out all new elements.
Another important implication worth mentioning is that you no longer have to wait until the page has loaded to assign events. Before, you had to wait until the document has loaded an element so JavaScript would know what the event handler was for. But now, timing doesn't matter; Event handlers can be added to CSS selectors in the head.
I'm excited to see where this will take us in JavaScript development. Let us know if you've used jQuery Live in any interesting places!



Add your comment below
Leave a Comment