I have a function A that does something (calls a web service in ajax request) and I have another function that is plugged in a calendar and that triggers on different events (click on day changes date, click on month changes calendar month… pretty typical calendar stuff).
The calendar works with classes: when the user clicks on a day item, the function that handles this event first determines the attr(‘id’) of the calendar that fired this event and then works on the calendar with this ID. There could be several calendars on the same page. When the user clicks on a date on a certain calendar, I want function A to execute. I could simply call function A from the calendar click functions by hard-coding the ID of the calendar and if the function executes on calendar ID xyz then do the regular things AND also call function A.
In general terms, what I want to do is create a jquery event listener that calls function A when a certain event is raised on one of my calendars. Something “listen to this function being executed on calendar xyz and when you hear something, call function A”. How do you setup an event listener like this in jquery?
Thanks for your suggestions.
You can use:
JS Fiddle demo of concept.
References:
delegate().