javascript - Call function in custom function -


i'm trying figure out how custom jquery functions work experimenting bit. can't work properly. i'm trying call prepareslide function in setinterval says prepareslide not defined

$('document').ready(function(){     jquery('.item_holder').itemslider({         start: 1,         carousel: true     }); }); $.fn.itemslider = function (details) {     var currentslidenumber = (details && details.start > 0) ? details.start : 1;     this.prepareslide = function(slidenumber) {         alert(1)     }     //set interval     var itemtoslide = currentslidenumber + 1;     slidetimer = setinterval("prepareslide(" + itemtoslide + ")", 5000); } 

you should provide function first argument of setinterval. also, provide context function invocation, quick method preserve this having variable reference it, in case, call self

var self = this;  slidetimer = setinterval(function(){   self.prepareslide(itemtoslide) }, 5000); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -