If I have a table with links to delete a record, which is the best way to wire up the click event? Do these evaluate the same under the hood?
$("#table").on("click", ".delete", function(){
//do stuff
});
or
$("#table .delete").click(function(){
//do stuff
});
No, they don’t.
In the way you are using them…
.on()The way you are using it (delegation), will save you cycles at attachment as well as memory, because it doesn’t actually attach the events in that moment, as it provides a dynamic element where the event is applied to future elements as well..click()will save you cycles at execution, as it explicitly attaches an event to every matching element at that moment in time, but in reality, this would be the last place I’d look for a bottleneck.Read some testing with event delegation here…
Performance testing of attaching event handlers…