I am confused when you need to use event delegation rather than jQuery event handling out of the box.
I am always tempted to use an event handler because it is so simple in jQuery:
For example:
$("button#submit").click(function () {
$(this).css("disabled", "true");
});
Event delegation is actually not that difficult to write:
$("button#submit").live("click", function() {
$(this).css("disabled", "true");
});
But that just doesn't seem intuitive.
Is there a simple rule about when to use event delegation? I think that I do not quite understand its essence.
source
share