1

I recently update my jquery library to 3.3.1 and since then the jquery.fileupload-ui breaks here

 _initEventHandlers: function () {
        $.blueimp.fileupload.prototype._initEventHandlers.call(this);
        var filesList = this.element.find('.files'),
            eventData = { fileupload: this };
        filesList.find('.start a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._startHandler
            );
        filesList.find('.cancel a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._cancelHandler
            );
        filesList.find('.delete a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._deleteHandler
            );
    },

My sense is that live is deprecated.

How can I modify this code as a way to fix this ?

Kind regards

Arianule
  • 8,811
  • 45
  • 116
  • 174
  • 1
    Possible duplicate of [jQuery 1.9 .live() is not a function](https://stackoverflow.com/questions/14354040/jquery-1-9-live-is-not-a-function) – Eddie Jun 02 '19 at 12:56

1 Answers1

2

Your feeling is correct, live() was deprecated a long time ago and has been removed.

The modern approach is to use the delegated signature of the on() method. Given your code, it would look like this:

_initEventHandlers: function() {
  $.blueimp.fileupload.prototype._initEventHandlers.call(this);
  var filesList = this.element.find('.files'),
    eventData = { fileupload: this },
    clickEventName = 'click.' + this.options.namespace;

  filesList.on(clickEventName, '.start a', eventData, this._startHandler);
  filesList.on(clickEventName, '.cancel a', eventData, this._cancelHandler);
  filesList.on(clickEventName, '.delete a', eventData, this._deleteHandler);
},
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339