1

I'm wring a jQuery plugin, and I want the divs created inside of the plugin can be customized the ids, which i mean:

this is what i've done:

(function($) {
    $.fn.plugin = function (options) {
        var defaults = {
            box_id = "nos-box_id",
           shoes_id = "nos-shoes_id"
    }
    ...
    ...
    ...
   return this;

})(jQuery);

and i want this:

(function($) {
    $.fn.plugin = function (options) {
        var defaults = {
            plugin_prefix = "nos-",
            box_id = _somethinghere_ + "box_id",
           shoes_id = _somethinghere_ + "shoes_id"
    }
    ...
    ...
    ...
   return this;

})(jQuery);

to make "somethinghere" equals to defaults.plugin_prefix(in this case, "nos").

can anybody help me figure this out?

Thx !

1 Answer 1

1

Don't build the id attributes until you have the prefix in hand. Leave plugin_prefix in your defaults but move box_id and shoes_id to somewhere else.

$.fn.plugin = function (options) {
    var defaults = {
        plugin_prefix: "nos-",
        // other options ...
    };
    options = $.extend({ }, options, defaults);

    var ids = {
        box_id:      options.plugin_prefix + "box_id",
        shoes_id:    options.plugin_prefix + "shoes_id",
        pancakes_id: options.plugin_prefix + "pancakes_id",
        // other ids you may need...
    };
    //...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.