Both the syntax used above are the same...... the .click()
is a short cut to the .on()
call
The difference is when you use the event delegation syntax which is supported by only .on()
Ex:
$(document).on("click", ".classname", function () {
var toAdd = $('input[name=checkListItem]').val();
});
When you use the syntax used by you it registers the handlers to only those elements which are present at the time when the code was executed, if a new element with the same class is added later then the handler will not be triggered if that one is clicked.
Event delegation is the solution for this problem... here we register the handler to a parent element which will be present in the dom with a filter criteria passed as the second argument... when the event gets bubbled upto the parent element it tests the target and its ancestors against the filter selector, if it is satisfied then the handler will get executed.