Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Problem with jQuery plugin defualt options

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #38552
    gilgimech
    Participant

    I’m using the jQuery plugin template from [CSS-Tricks](https://css-tricks.com/snippets/jquery/jquery-plugin-template/ “CSS-Tricks”), but I’m having a problem with the default options.

    (function ($) {
    $.lilRWDMenu = function (el, options) {
    var base = this;
    base.$el = $(el);
    base.el = el;
    base.$el.data(“lilRWDMenu”, base);
    $.lilRWDMenu.defaultOptions = {
    mainMenuClass: ‘main-menu’,
    rwdMenuClass: ‘rwd-mobile-menu’
    };
    base.init = function () {
    base.options = $.extend({}, $.lilRWDMenu.defaultOptions, options);
    };
    base.init();
    };
    $.fn.lilRWDMenu = function (options) {
    return this.each(function () {

    var mainMenuObj = options.mainMenuClass,
    rwdmenuObj = options.rwdMenuClass;
    console.log(mainMenuObj );
    console.log(rwdmenuObj);
    });
    };
    })(jQuery);

    For some reason the default options are coming back as ‘undefined’.

    I can’t figure out why it’s not working, so if anyone can check my code for me that’ll be great.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.