I’m trying to create a interval call to a function in jQuery, but it doesn’t work! My first question is, can I mix common JavaScript with jQuery?
Should I use setInterval("test()",1000); or something like this:
var refreshId = setInterval(function(){
code...
}, 5000);
Where do I put the function that I call and how do I activate the interval? Is it a difference in how to declare a function in JavaScript compared to jQuery?
To write the best code, you “should” use the latter approach, with a function reference:
or
but your approach of
is basically valid, too (as long as
test()is global).Note that there is no such thing really as “in jQuery”. You’re still writing the Javascript language; you’re just using some pre-made functions that are the jQuery library.