Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9043841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:49:47+00:00 2026-06-16T10:49:47+00:00

Possible Duplicate: How would you change this kind of code? How would I pass

  • 0

Possible Duplicate:
How would you change this kind of code?

How would I pass these variables in to options through jQuery, so that when the user uses the plugin, they must initialize the plugin from the HTML like so:

 <script>
    $('.elem').pluginName({
       theme: 'blue',
       animSpeed: 200
    });
 </script>

Here’s my jQuery code. Pretty messy, but have a look. How could I change the variables to options?

$(function () {

    var theme = "sunburst";
    var btnColor = "yellow";
    var icon = "power";
    var message = "Hello World";
    var animSpeed = 300;
    var animType = 'fadeIn';
    var btnText = "Purchase";
    var btnLink = 'http://www.google.com';
    var closeStyle = "dark";

    var content =
        '<div id="mn_close" class="' + closeStyle + '"></div>' +
        '<div id="mn_border"></div>' +
        '<i class="icon-' + icon + '"></i>' +
        '<span class="mn_message">' + message + '</span>';
        //  '<a href="' + btnLink + '" class="button ' + btnColor + '">' + btnText + '</a>';


    $("#mn_close").live("click", function () {
        $('.mn_bar').animate({
            height: '0'
        }, animSpeed, function () {});
    });
    var mn_bar = $(".mn_bar");
    mn_bar.append(content);
    $(function () {
        mn_bar.addClass("animated");
        mn_bar.addClass(animType);
        mn_bar.addClass(theme)
    });
});

Or here is the jsfiddle. http://jsfiddle.net/LwGRV/6/

I’ve being trying to implement the code in to this standard type of jQuery code too, but failing to merge:

;(function ( $, window, document, undefined ) {
    var pluginName = "defaultPluginName",
        defaults = {
            propertyName: "value"
        };

    function Plugin( element, options ) {
        this.element = element;

        this.options = $.extend( {}, defaults, options );

        this._defaults = defaults;
        this._name = pluginName;

        this.init();
    }

    Plugin.prototype = {

        init: function() {
        },

        yourOtherFunction: function(el, options) {
            // some logic
        }
    };

    $.fn[pluginName] = function ( options ) {
        return this.each(function () {
            if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName, new Plugin( this, options ));
            }
        });
    };

})( jQuery, window, document );

Many thanks in advance if anyone can shed some light on to this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:49:49+00:00Added an answer on June 16, 2026 at 10:49 am

    You should have a look at this: http://api.jquery.com/jQuery.extend/
    Your variables should be stored within an object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Where do I change the setting in Eclipse so that it would
Possible Duplicate: jQuery attribute selector for multiple values I have this $('input:radio[name=foo]').change(function() { blah();
Possible Duplicate: jQuery Browser Compatability (IE) I would initially post some code snippets (and
Possible Duplicate: How to delete a ‘git commit’ Knowing that this will change history,
Possible Duplicate: passing in object by ref With the code below, the output would
Possible Duplicate: Change path.expand location (Win 7) I would like to change the directory
Possible Duplicate: How would i change the width of the snake in my “snake
Possible Duplicate: mod_rewrite, php and the .htaccess file Would like this to happen in
Possible Duplicate: C++ source in unicode I just discovered this line of code in
Possible Duplicate: Use jQuery to change an HTML tag? I have searched around for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.