Search code examples
javascriptjqueryfullcalendarfullcalendar-scheduler

Fullcalendar can't access html5 data attribute in drop, only on Firefox


I have fullcalendar setup to grab the html5 data attribute "event" from external events. For reasons unnecessary to get into, I am needing to access that data in the drop event handler in fullcalendar, but when I use var foo = $(this).data(event);, it seems to stop the script at that point, but only in Firefox, and no errors show in the console.

Here is a jsfiddle showing it. For some reason, the calendar isn't working right, but that is not my problem. The problem shows itself when you drop the event anywhere on the calendar. In chrome, you will see a total of 3 alert boxes. In Firefox, only two.


Solution

  • You are using the wrong method here.

    .data() is for storing arbitrary data,

    Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.
    […]
    The .data() method allows us to attach data of any type to DOM elements

    This "data store" has little to do with HTML5 data attributes.

    To read those, you should simply use: $(this).attr('data-event')