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 8874339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:41:43+00:00 2026-06-14T18:41:43+00:00

My plugin has to do different things for each object, and at the same

  • 0

My plugin has to do different things for each object, and at the same time I need to be able to call various methods, and do many other things.

What I want to happen here is, that when a user clicks on the first button it should call the function for test_one div not for test_two.

My code on jsFiddle:

<button class="test_one">First</button >

<button class="test_two">Second</button >

<div class="called_for"></div>
(function($){
    var globalSettings = {
        success: function(){}
    };

    var methods = {
        init : function(options){
            settings            = $.extend({},globalSettings,options);

            $(this).click(function(){
                settings.success();                
            });                
        }                
    }

    $.fn.test = function(method, options){
        if(methods[method])
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        else if(typeof method === 'object' || !method)
            return methods.init.apply(this, arguments);
        else
            $.error('Method ' + method + ' does not exist');
    };

})(jQuery);


$(".test_one").test({
    success: function(){
        $(".called_for").text("I got called for 'test_one'");
    }
});


$(".test_two").test({
    success: function(){
         $(".called_for").text("I got called for 'test_two'");
    }
});

​

  • 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-14T18:41:44+00:00Added an answer on June 14, 2026 at 6:41 pm

    You didn’t declare settings, so it was global and thus overwritten by the second plugin call. Do use var: http://jsfiddle.net/q6e38/4/.

    var settings = $.extend({}, globalSettings, options);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Hibernate: different object with the same identifier value was already associated with
I am working with a jQuery plugin that has the following snippet in it:
Does anyone know of a jQuery plugin that has 'helpers' or extensions like those
I'm using a jQuery plugin that has its functions defined as such: $('#mydiv').pluginAction({ someproperty:
I'm working with a jQuery plugin that has this: var $el = $(this), $wrapper
I'm looking for a jQuery plugin that has similar functions as Chosen (the multiple
Can some give me good jQuery lightbox plugin which has zoomin and zoomout function
The Paperclip plugin for Rails has a resize option that keeps the image in
I have an Eclipse plugin project that has several file resources that I would
I am using Jquery Cycle Plugin and it has a side panel that highlights

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.