Reputation: 5795
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?
Upvotes: 2
Views: 6483
Reputation: 4775
Just try the following pattern:
$.fn.myplugin = function(options) {
var settings = $.extend({}, options);
alert(settings.name + " , " + settings.value);
};
Upvotes: 1
Reputation: 31920
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
Upvotes: 5