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?
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?
Share Improve this question asked Jun 14, 2013 at 20:59 user123_456user123_456 5,82526 gold badges87 silver badges142 bronze badges2 Answers
Reset to default 5when 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
Just try the following pattern:
$.fn.myplugin = function(options) {
var settings = $.extend({}, options);
alert(settings.name + " , " + settings.value);
};