In jQuery this is a very simple click event that prints to the console when clicked:
First thing you should notice is that the callback function inside the click function is an anonymous function. There is no easy way of cleaning it up after you have done with it, whenever that might be. Thats why it is in general bad practice to use anonymous functions. so lets improve our code:
Perfect, it already looks cleaner and now we have a reference variable we can use for that specific click event. Now if I wanted to remove that specific click event I would just:
This technique is very useful when you have so many click events assigned to a selector and you can’t
$('#some-button-id').unbind('click') because it would get rid of all the click events.