fellow coders, assuming that I have a button with a click handler like so:
$("#save-item-btn").click(function() { saveItemDialogData(true); });
if the same code is executed again, would jquery realize that, clear the previous bind and reapply it or would it consume resources or cause unnecessary side effects?
thanks
Every time you call click(), it will bind the function you give it to that handler — it can’t tell that the function is the same. If you want to be sure that there are no prior click handlers on your button, first call unbind(‘click’) on it and then attach your click handlers.
Note that assigning to the onclick property directly will replace the existing handler with whatever you assign to it; allowing multiple functions to be bound to the same event is a jQuery feature.