Q:

Call external function with parameter in onswipe jquery

I have a function that already defined. I need to to call the function with parameters when the jQuery swipe event occurs.
Here is the code
$( document ).ready(function() {
  $("#next").on("swiperight",myFunction('right')); 
  $("#next").on("swipeleft",myFunction('left')); 

  function myFunction(direction) {
    var dir = direction;
    console.log(dir);
  }
});

But id doesn't works onswipe. Instead it works twice on page load and prints right and left in console.
It works when the function is called without arguments like,
$("#next").on("swipeleft",myFunction);

What is the problem here ? Appreciate for any help.

A:

Callback functions have no name. Wrap your named functions inside it:
  $("#next").on("swiperight",function(){myFunction('right')}); 
  $("#next").on("swipeleft",function(){myFunction('left')});

