Search code examples
javascriptjquerybxslider

Call function inside bxslider callback


I am trying to call a custom function inside a bxslider callback but the function doesn't get recorgnized (aka: Uncaught Reference Error: nextSlideCustom() is not a function)

my current code looks like

    var slider=$('#slider1').bxSlider({
         pager: 'true',
         onSlideNext: nextSlideHandle()
    });

and in a different js file I am defining this function:

function nextSlideHandle(){
    console.log("huhu");
}

so what's the problem with my code, or is it mory likely a wrong configuration of the slider or something?

thanks in advance!


Solution

  • make sure nextSlideHandle is defined before calling bxSlider, and also do it without parantheses, because that way, you're passing the result of the function and not the function itself, hence; undefined function error.

    var slider=$('#slider1').bxSlider({
         pager: 'true',
         onSlideNext: nextSlideHandle
    });