JavaScript how to send parameters to jquery plugin function send params jquery,send parameters ajax jquery,send parameters post

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?

Answer:1

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

Answer:2

So I am trying to keep all my functions in 1 jQuery file. Still learning jQuery btw However I'm running into problems where a div id doesn't exist on a different page and it throws and error. I use ...

So I am trying to keep all my functions in 1 jQuery file. Still learning jQuery btw However I'm running into problems where a div id doesn't exist on a different page and it throws and error. I use ...

I've got a template with two kind of article-container: Viewer and Editor: <article ng-if="!editor" ng-controller="article"> <div>Some content</div> </article> <...

I've got a template with two kind of article-container: Viewer and Editor: <article ng-if="!editor" ng-controller="article"> <div>Some content</div> </article> <...

JS FIDDLE I have a function as follows in javascript function myfun() { var a = "'\u0c39"; alert(a); } When i called this function i am able to see correct letter(This letter is telugu ...

JS FIDDLE I have a function as follows in javascript function myfun() { var a = "'\u0c39"; alert(a); } When i called this function i am able to see correct letter(This letter is telugu ...

  1. unable to convert unicode to string

[updated] given object: var node = { 'comments': 'http://example.com/post/#comments', 'slash:comments': '143', } One can access the 'title' parameter using indexed access or dot notation: node["...

[updated] given object: var node = { 'comments': 'http://example.com/post/#comments', 'slash:comments': '143', } One can access the 'title' parameter using indexed access or dot notation: node["...