$("p").live("click", function(){
$(this).css("color", "red");
});
The reason this is smarter is because there are likely many p elements on the page. If there were, say, 10 of them, traditional click event binding would require 10 handlers. The live function only requires one, reducing memory needed by the browser. Then imagine compounding the issue by 100 (for example, a table with 1000 cells with hover events).
Additionally, using the live function does not require events to be re-bound when additional elements are added to the page (like via AJAX).
Just a heads up that .live() is now depreciated in jQuery 1.7 and up. Instead you need to use the .on() method instead.
big like
“live” is deprected, use “on” instead
Hey people this live method is deprecated officially by jQuery.
Now we use .on() method to replicate .live() functionality.