NovelProjects

Tuesday, February 3, 2009

jQuery live function

I think this is pretty awesome. With the new update from jQuery (1.3.1), you can now add an event handler to a set of elements that are currently on the page, and in the future. With the rise of AJAX applications, this is going to make a lot of jobs incredibly easier.



To put it in non-HTML terms, let's say you wanted to give a child a piece of candy if their name began with the letter 'a'. Previously, you would have to do a census of all the children, find which children fit your criteria, and then give them candy. Once the candy was dispersed, that was it. No more candy. Now comes along jQuery that can handle giving out all the candy to the current children and all future children with names that begin with the letter 'a'. And you don't have to do any additional work.



The new function looks like it can replace the current bind() function format, but you get all the new goodness. Here's an example from jQuery's web site:



$("p").live("click", function(){
$(this).after("<p>Another paragraph!</p>");
});

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.