0

I have my own jquery plugin for my app. Its working fine for first callbacks and the second callbacks are not assigning.

$('element1').myplugin({callback:foo});
$('element2').myplugin({callback:bla});

second callback not working always calling 'foo'.

plugin code:

(function($) {
    $.fn.myplugin = function(options) {
          //some code.
          options.callback();
        }
})(jQuery);
3
  • 2
    It sounds like there's a bug with your plugin. Can you post the source code (the minimum amount it takes to still see the bug)? Commented Aug 13, 2012 at 11:08
  • 3
    Yeap - impossible to answer without seeing plugin code. Commented Aug 13, 2012 at 11:09
  • look at now the question Commented Aug 13, 2012 at 11:10

2 Answers 2

1

if you include any javascript then use upgraded version and also verifies the request which u pass and what u get in response....also make sure if there are one or more javascript include then use $.noConflict(true); may be this was help full to u........

Sign up to request clarification or add additional context in comments.

2 Comments

can u give example i cant understand wt you are saying
Sorry i dont have any perticuler exapmle for this but i use this one and solve this type of error
1

Add (jQuery) at the end of the plugin. Demo: http://jsfiddle.net/wLEEK/
Here's why that works. Right now, your plugin looks like this:

(function($) {
  $.fn.myplugin = function(options) {
      //some code.
      options.callback();
    }
})(jQuery);

You're creating the jQuery method myplugin. But notice the code on the first line function ($) { and on the last line }. You've wrapped the plugin creation code in a function. The function accepts one argument that you call $. So the plugin creation code is inside a function, so we call that function using (jQuery) - passing in jQuery as an argument. It's kinda complicated, but here's a more familiar form to help you understand what's going on:

function createPlugin ($) {
  $.fn.myplugin = function(options) {
      //some code.
      options.callback();
    }
}//end of createPlugin
// myplugin isn't created yet; we need to call the function createPlugin
createPlugin(jQuery) // now myplugin is created

2 Comments

why jquery adding can u explain
If it's still not working can you create a test on jsfiddle.net? Thanks.

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.