$.fn.myplugin = function(option) { // 引数をalert alert(option.hoge); var elements = this; elements.each(function() { $('body').append('<p>Message: ' + this.innerHTML + '</p>'); }); return this; };
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>My plugin | Learning jQuery plugin</title> <style> p { color: #4c5069; font-size: 3em; } </style> </head> <body> <div>Hello, world!</div> <script src="./hello.js"></script> <script> $('div').myplugin({'hoge':1}); </script> </body> </html>
myplugin関数に、JSONを突っ込めていることを確認しました。