Aaron Aaron - 1 year ago 258
jQuery Question

FullCalendar Remove External Event by ID

I am using FullCalendar and jQuery UI to drag "Days Off" onto my calendar as background events.

Since you cannot click on background events in FullCalendar, I am creating a list with my days off and a "Remove" button next to them with the event id as a data attribute.

However, when I click on the Remove button, it does not remove the event, even though it has the proper ID.

Please take a look at this jsFiddle: https://jsfiddle.net/aaroncadrian/odhL964L/

For the sake of showing you that the event ID has been properly updated, I removed the background rendering of the event so that you can click on the event to reveal its ID. You can also see the event ID on the button and in its data-id attribute. Here is the code for removing the event, which does not work.


var id = $(this).data('id'); // Get the ID for the event from the button

$('#calendar').fullCalendar('removeEvents', id); // Remove the event. **DOES NOT WORK**


Can you please let me know how I can remove an event by clicking on its corresponding button? Again, ideally I'd like for these events that are being dragged on to be rendered as background events.


I added an event and its corresponding button to the page at load, and the function to remove the event works since the event was rendered on page load. So what do I need to do differently so that external events that were dropped onto the calendar will be removable in the same way?

Answer Source


Changed your

var button = '<button class="remove" data-id="' + event.id +'">Remove (' + event.id + ')</button>'; // Create remove button with data-id attribute with event ID


var button = '<button class="remove" data-id="' + event._id +'">Remove (' + event.id + ')</button>'; // Create remove button with data-id attribute with event ID

and the



$('#daysOff').on('click', 'button.remove', function(){

to get it removing the items from calendar.

Not sure why using the internal event _id works where your assigned id one wasn't working.

You can also remove the li date/button entry with $(this).parent().remove(); inside the click handler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download