2619 2619 - 4 months ago 7
Javascript Question

my jquery code doesnt work. why?

Here is my jquery code and it does not work. I really dont know why. Please help and also tell me how can I fix it.

$(function () {
var panel = function () {
var init = function () {
console.log('hello');
};

return {
init: init
}
};

$('.nav li a').on('click', function (e) {
panel.init();
});

})();


I am getting this error in my console

Object function () {
var panel = function () {
var init = function () {
console.log('hello');
}
};

return {
init: init
}
} has no method 'init'

Answer

I think you are missing the parentheses off of the end of the panel function declaration.

var panel = function () {
    var panel = function () {
        var init = function () {
            console.log('hello');
        }
    };

    return {
        init: init
    }
}();

Make sure the closing brace is followed by ()

Comments