I can’t get before & after callbacks to work with the cycle plugin for jQuery!
I’m not sure what’s going wrong, i even tried using the sample code from the documentation.
Here’s the code:
$(document).ready(function(){
function onBefore() { alert('before'); }
$('.slideshow').cycle({
before: 'onBefore'
});
});
and it throws an error: “Error: opts.before[0].apply is not a function”
and in chrome: “Uncaught TypeError: Object onBefore has no method ‘apply'”
what is happening!?
The error is because
.apply()is a method on functions, not on strings…and'onBefore'is a string. Instead, don’t use a string…use a direct reference, like this:Or an anonymous function: