Shivam
Shivam

Reputation: 2248

jQuery Plugin variable undefined

I am working on creating my first jQuery based plugin but I am stuck at an issue.

I receive an error stating var minHeight is undefined when I am trying to console.log it.

(function ($) {
    $.fn.ezToggle = function (options) {
        var defaults = {
            selector: $('.selector'),
            minHeight: defaults.selector.height(),
            speed: 200
        }
        console.log(defaults.minHeight); // appears undefined       
    };
})(jQuery);

Upvotes: 0

Views: 165

Answers (2)

Wilker Iceri
Wilker Iceri

Reputation: 487

Use the selector in attribute minHeight too:

minHeight: $('.selector').height();

Upvotes: 1

Brian Lewis
Brian Lewis

Reputation: 5729

You need to make sure to check that selector is defined.

Upvotes: 0

Related Questions