0

I am trying to call a function with a param:

This is the function:

var showCustomTooltip = function(e, param) {
    param.show(function() {...});
};

and this is how I am trying to call it:

$t1btn.on('click', {param: $('.t1')}, showCustomTooltip);

But is the error I am getting in the console:

Uncaught TypeError: Cannot read property 'show' of undefined

What am I doing wrong?

2
  • this may indicate that your selector found nothing. Have you placed your code in $(document).ready() ? Commented Sep 27, 2017 at 21:41
  • console.log the param inside function call Commented Sep 27, 2017 at 21:42

1 Answer 1

1

Look here:

var showCustomTooltip = function(e, param) {
    param.show(function() {...}); // param is undefined
};

Instead:

var showCustomTooltip = function(e) {
    e.data.param.show(function() {...});
};

jQuery docs example:

function greet( event ) {
  alert( "Hello " + event.data.name );
}
$( "button" ).on( "click", {
  name: "Karl"
}, greet );
$( "button" ).on( "click", {
  name: "Addy"
}, greet );
Sign up to request clarification or add additional context in comments.

1 Comment

@zmii The docs are referenced in the first line. Is not clear enough?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.