tags:

views:

41

answers:

5

According to [[ http://plugins.jquery.com/project/timeout_interval_idle ]], I should be able to say:

$.interval(function() { alert('I happen every 8 seconds'); }, 8000);

and have the given function run every eight seconds.

However the error console says "$.interval is not a function". I have tried this under jQuery 1.4.2 and 1.4.3, both give the same error.

What am I doing wrong?

+4  A: 

Simply try setInterval:

window.setInterval(function() {
  alert('I happen every 8 seconds');
}, 8000);

use clearInterval to stop. You might have a look at mozilla's developer center for more information.

pex
+2  A: 

That's a plugin that has to be included after jQuery core.

However it's not needed, a simpler setInterval() will do (no jQuery required), like this:

setInterval(function() { alert('I happen every 8 seconds'); }, 8000);

You can test it out here.

Nick Craver
A: 

This is not a standard jQuery operator but instead a function provided by the referenced plugin. It won't be available unless you explicitly import the plugin into your code base.

Alternatively you could just use the setInterval function directly.

setInterval(function() { alert('I happen every 8 seconds'); }, 8000);
JaredPar
A: 

Use setTimeout() instead of $.interval()

XSaint32
a timeout is not the same as an interval, a timeout executes *once*.
Nick Craver
A: 

Did you include the plug in code in your page? This isn't part of jQuery itself, so you need to make sure you have the plugin file either linked to as a separate script or inline in your page.

I'm not sure what functionality this plugin offers beyond what the standard window.setInterval function does.

Alex JL
This plugin seems to be founded on ignorance. From its docs: *"These functions [setTimeout and setInterval] are very useful, but unfortunately they only accept code as a string."* It's apparently too easy to create jQuery plugins.
patrick dw
@patrick Ha, oh no... I GUESS that's true, if you're using IE4 or Netscape 3...
Alex JL