user3173305
user3173305

Reputation: 33

jQuery .on() method with multiple events - passing argument to event handler function

Here is the code :

$('.el')
    .drag("init", function () {
        //
    })
    .drag("start", function () {
        //
    })
    .drag("end", function () {
        //
    });

I couldnt find a way to pass the parameters in the case below

$('.el').on({

   drag: function(){
       //*init* functions  
   },

   drag: function(){
       //*start* functions  
   },

   drag: function(){
       //*end* functions  
   }

})

Is it possible to pass parameters while using on event delegation for multiple events at once. Or the only solution is using on for multiple times.

Upvotes: 0

Views: 121

Answers (1)

adeneo
adeneo

Reputation: 318202

You should probably lead with the fact that you're using a plugin, more specifically this plugin.

The docs are pretty clear, there are events built in, such as draginit, dragend etc. that can be used instead of the drag() method

$(document).on({

   draginit: function(){
       //*init* functions  
   },

   dragstart: function(){
       //*start* functions  
   },

   dragend: function(){
       //*end* functions  
   }

}, '.el');

Upvotes: 2

Related Questions