2

I want to pass values to jquery plugin function.

This is my plugin:

(function ( $ ) {

    $.fn.myplugin = function(name,value) {
        alert(name + " , " + value )
    };

}( jQuery ));

And this is my call:

$('#wrapper').myplugin({name:'test',value:'big_test'});

I can't receive any data in my plugin. why?

2 Answers 2

5

when you are sending data as object then receive it as object and change your plugin code like

$.fn.myplugin = function(data) {
        alert(data.name + " , " + data.value )
    };

Note:Don't forget to return $(this) object in order to mantain chain ability of jQuery

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

2 Comments

thank you...it was right in front of me and I didn't realize it :)
should I return this or $(this)
1

Just try the following pattern:

    $.fn.myplugin = function(options) {
        var settings = $.extend({}, options);

        alert(settings.name + " , " + settings.value);
    };

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.