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

  • Home
  • SEARCH
  • 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 3358114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:42:47+00:00 2026-05-18T02:42:47+00:00

I have a JQuery 1.4.2 plugin, that uses a set of options. It’s pseudo

  • 0

I have a JQuery 1.4.2 plugin, that uses a set of options. It’s pseudo code is like this:

 (function($) {
  // Shell for the plugin code
  $.fn.myPlugIn = function(options) {
    // Plugin code
    return this.each(function() {
      // for each item in selector
      options = $.extend($.fn.myPlugIn.defaults, options);
      ...do stuff
    });
    $.fn.myPlugIn.defaults = {
    header      :   null,
    position    :   'absolute',
    top         :   null,
    left        :   null,
    forinput    :   null,
    forAnchor   :   null,
    sAjaxSource :   null,
    onClick     :   null
  };
  })(jQuery);

When calling the plugin for several elements on a single page, the options are not unique — the previous elements options are still in the options.

$(document).ready(function() {
    $("#div1").myPlugIn(
            {forinput: "input1",
             onClick: function(data){
                ... do stuff
            },
    });
    $("#div2").myPlugIn({
          forAnchor: "link1",
            onClick: function(data){
                ... do stuff
             },
        header: "Parts"
    });

});

What am I doing wrong? I expected that each time the plugin was found, it would use the options passed to it. Instead, it uses retains all the options from the first instance and overwrites any re-initialized properties from the second instance.

Any replies are appreciated. Thanks in advance for reading my post.

  • 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-05-18T02:42:48+00:00Added an answer on May 18, 2026 at 2:42 am

    You need to merge the options into a new object for that instance, like this:

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

    $.extend() merges into the first argument all objects passed as parameters after that, so currently they’re merging into your $.fn.myPlugIn.defaults defaults, leaving it tainted for the next use. Instead you want to never mess with the defaults (unless intentionally changing them elsewhere) and merge the options and defaults into another new object.

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

Sidebar

Related Questions

I have a form that uses the excellent jQuery validation plugin. This is a
Ok so i have a text field that uses this jQuery watermark plugin which
I have a function called Colorbox (jQuery plugin) that takes a number of parameters
I have been trying to make this to be a little jQuery plugin that
In my local machine i have a scaffold that uses Jquery Validation plugin for
I have been working on a jquery plugin that uses a HTML5 audio player
I have a page that uses the jQuery.swfobject plugin to embed 5 flash items
I have a jQuery plugin that uses a needle gauge. Upon initially loading a
I have a slideshow that uses the Jquery cycle plugin. example of slideshow is
I have a website that uses the jQuery Address plugin from Asual for navigation.

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.