James Craig
James Craig

Reputation: 6854

Custom jQuery Plugin Error But Still Works

I'm making a jQuery slider plugin and it works, however I keep getting this error in the JavaScript console:

Uncaught TypeError: Object [object Object] has no method 'interval' 

The error says it's coming form these two lines (the code in-between each curly bracket):

if(settings.interval) {
    $(this).interval(settings.interval);    
}

if(settings.transition) {
    $(this).transition(settings.transition);
}

This is my first jQuery plugin and I can't figure the problem out. Any ideas what's causing the error?

Here is the code in action JS Fiddle

Upvotes: 0

Views: 28

Answers (2)

Patrick Berkeley
Patrick Berkeley

Reputation: 2286

Like janfoeh mentioned you don't need the lines you quoted in your question. The reason they have those checks in the tutorial you linked to is because those settings options are set to null by default. But for your plugin, those settings are not optional i.e., if you didn't have values for them, your plugin wouldn't do anything.

So I suggest setting defaults for the interval and timeout options and allowing them to be overridden instead of requiring them to be set ever time you use the plugin. See here: http://jsfiddle.net/48xDy/

Upvotes: 1

janfoeh
janfoeh

Reputation: 10328

Just remove the lines you quoted above - they have no purpose. I have updated your fiddle.

Upvotes: 0

Related Questions