Reputation: 3333
I'm trying following code to create a plugin. I'm getting error at the line if(options.controls == true)
The error I get is 'options is not defined
'.
How should I define it?
(function($) {
$.fn.jwslider = function(options){
var defaults = {
controls: true
};
var options = $.extend(defaults, options);
}
init();
function init()
{
if(options.controls == true)
{
alert("controls true");
}
}
}(jQuery));
Upvotes: 1
Views: 1159
Reputation: 2535
(function($) {
$.fn.jwslider = function(options){
var defaults = {
controls: true
};
var options = $.extend(defaults, options);
init();
function init()
{
if(options.controls == true)
{
alert("controls true");
}
}
}
}(jQuery));
Then the options
is accessible inside init
function
Upvotes: 1
Reputation: 172638
You have to define the options
variable outside the scope of function.
Currently it is defined in the scope of $.fn.jwslider
hence it is giving the error.
Upvotes: 1